I am trying to set up forever-monitor.
I added this to my app.js:
var forever = require('forever-monitor');
var child = new(forever.Monitor)('app.js', {
max: 3,
silent: true,
options: []
});
child.on('exit', function() {
console.log('app.js has exited after 3 restarts');
});
child.start();
However when I start my application from the command line it logs 'app.js has exited after 3 starts' but it still runs. In which file should this code be placed? Am I missing something about the usage of forever-monitor?
Here's how forever-monitor works
app_fm.js
var forever = require('forever-monitor');
var child = new(forever.Monitor)('app.js', {
max: 3,
silent: true,
options: []
});
child.on('exit', function() {
console.log('app.js has exited after 3 restarts');
});
child.start();
app.js
// put in all your great nodejs app code
console.log('node app is now running');
Now from the CLI start your app by typing
node app_fm
Honestly, I just use forever
and don't both with forever-monitor
(though I know it talks about it in the forever docs!). I create a file called start.js
and run my app with node start.js
.
'use strict';
var forever = require('forever');
var child = new (forever.Monitor )('app.js', {
//options : options
} );
//These events not required, but I like to hear about it.
child.on( "exit", function() {
console.log( 'app.js has exited!' );
} );
child.on( "restart", function() {
console.log( 'app.js has restarted.' );
} );
child.on( 'watch:restart', function( info ) {
console.error( 'Restarting script because ' + info.file + ' changed' );
} );
//These lines actually kicks things off
child.start();
forever.startServer( child );
//You can catch other signals too
process.on( 'SIGINT', function() {
console.log( "\nGracefully shutting down \'node forever\' from SIGINT (Ctrl-C)" );
// some other closing procedures go here
process.exit();
} );
process.on( 'exit', function() {
console.log( 'About to exit \'node forever\' process.' );
} );
//Sometimes it helps...
process.on( 'uncaughtException', function( err ) {
console.log( 'Caught exception in \'node forever\': ' + err );
} );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.