2016-08-31 19:31:59 +00:00
|
|
|
var forever = require('forever-monitor');
|
|
|
|
var fs = require('fs-extra');
|
|
|
|
|
|
|
|
var getDateTimeString = () => {
|
|
|
|
var date = new Date();
|
|
|
|
var hour = date.getHours();
|
|
|
|
hour = (hour < 10 ? "0" : "") + hour;
|
|
|
|
var min = date.getMinutes();
|
|
|
|
min = (min < 10 ? "0" : "") + min;
|
|
|
|
var year = date.getFullYear();
|
|
|
|
var month = date.getMonth() + 1;
|
|
|
|
month = (month < 10 ? "0" : "") + month;
|
|
|
|
var day = date.getDate();
|
|
|
|
day = (day < 10 ? "0" : "") + day;
|
|
|
|
return year + "-" + month + "-" + day + "_" + hour + "-" + min;
|
|
|
|
};
|
2016-08-31 20:21:12 +00:00
|
|
|
var log_forever = './log/forever_'+getDateTimeString()+'.log';
|
|
|
|
var log_bot = './log/bot_'+getDateTimeString()+'.log';
|
2016-08-31 19:31:59 +00:00
|
|
|
var putlog = (msg) => {
|
2016-08-31 20:21:12 +00:00
|
|
|
fs.appendFileSync(log_forever, msg, 'utf8');
|
2016-08-31 19:31:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var child = new (forever.Monitor)('./src/main.js', {
|
2016-08-31 20:21:12 +00:00
|
|
|
max: 1,
|
2016-09-08 15:42:38 +00:00
|
|
|
silent: false,
|
2016-08-31 20:21:12 +00:00
|
|
|
args: [],
|
|
|
|
watch: true,
|
|
|
|
watchIgnoreDotFiles: true,
|
|
|
|
watchIgnorePatterns: [
|
2016-08-31 20:27:03 +00:00
|
|
|
'*.log', 'b/*', 't/*'
|
2016-08-31 20:21:12 +00:00
|
|
|
],
|
|
|
|
watchDirectory: __dirname,
|
|
|
|
logFile: log_bot,
|
|
|
|
outFile: log_bot,
|
|
|
|
errFile: log_bot
|
2016-08-31 19:31:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
child.on('watch:restart', (info) => {
|
2016-08-31 20:21:12 +00:00
|
|
|
putlog('Restaring bot because ' + info.stat + ' changed\n');
|
2016-08-31 19:31:59 +00:00
|
|
|
});
|
|
|
|
child.on('restart', () => {
|
|
|
|
putlog('restarting bot for ' + child.times + ' time\n');
|
|
|
|
});
|
|
|
|
child.on('start', () => {
|
|
|
|
putlog('starting bot\n');
|
|
|
|
});
|
|
|
|
child.on('exit:code', (code) => {
|
|
|
|
putlog('detected bot exited with code ' + code + '\n');
|
2016-09-01 07:56:53 +00:00
|
|
|
child.restart();
|
2016-08-31 19:31:59 +00:00
|
|
|
});
|
|
|
|
child.start();
|