Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created October 9, 2011 00:59
Show Gist options
  • Save indexzero/1273127 to your computer and use it in GitHub Desktop.
Save indexzero/1273127 to your computer and use it in GitHub Desktop.
A simple hook to restart a process if it is hung (i.e. non-responsive)
var forever = require('forever'),
request = require('request');
function checkIsHung (monitor) {
//
// Do something to check if your process is hung
// e.g. Make an http request
//
request({ uri: 'http://yourapp.com' }, function (err, res, body) {
if (err) {
monitor.restart();
}
});
};
function hungHook (monitor) {
monitor.on('start', function () {
//
// Check if your process is hung every 30 seconds
//
setInterval(checkIsHung.bind(monitor), 30000);
});
}
forever.start('your-script.js', {
//
// Include other forever options here
// see README.md for details of all
// options
//
hooks: [hungHook]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment