How to use forever-monitor in node

Asked 2 years ago, Updated 2 years ago, 54 views

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();

node.js forever-monitor

2022-09-22 22:05

1 Answers

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


2022-09-22 22:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.