From node
I made monitor.js after seeing forever-monitor on github
/* monitor.js */
var forever = require('forever-monitor');
var time = require('./time');
var maxRestart = 20;
var now = time.getFormString();
var child = new (forever.Monitor)('app.js', {
max: maxRestart,
silent: true,
args: [],
'logFile':'log/'+now+'.log',
'outFile':'./'+now+'.out',
'errFile':'./'+now+'.err'
});
child.on('restart', function() {
console.log(time.getKoreaString() + ', forever restart');
});
child.on('exit', function () {
console.log(time.getKoreaString() + ', app.js has exited after'+ maxRestart+' restarts');
});
child.start();
If you are not running within the program, I think you should use forever
instead of forever-monitor
. To run as set above
TIME=`date +%Y%m%d%H%M%S`
forever start -m 20 -s -l log/$TIME.log -o $TIME.out -e $TIME.err app.js
To stop running, you can run forever stop app.js
. In addition, the execution log of forever is output to log/$TIME.log
and the results output from the app are output to $TIME.out
.
https://github.com/foreverjs/forever
© 2024 OneMinuteCode. All rights reserved.