Created
July 25, 2012 17:50
-
-
Save treygriffith/3177501 to your computer and use it in GitHub Desktop.
Auto-restart Nodejs server and notify Airbrake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Auto-restart Nodejs server a few times so a random error doesn't kill everything | |
var forever = require('forever-monitor'); | |
// set up airbrake for notifications when the server dies | |
var airbrake = require('airbrake').createClient("CLIENT_ID"); | |
var server = new (forever.Monitor)('server.js', { | |
max: 5, | |
silent: false, | |
options: [] | |
}); | |
server.on('exit', function () { | |
console.log("server.js fully down after 5 starts."); | |
console.log("SERVER DOWN."); | |
airbrake.notify(new Error("SERVER DOWN: Forever restarts exhausted"), function(err, url) { | |
// Throw an error if Airbrake delivery failed - server is dead anyway | |
if (err) throw err; | |
// Error has been delivered, url links to the error in airbrake | |
console.log("Airbrake: Notified service:", url); | |
}); | |
}); | |
server.on('exit:code', function(code) { | |
console.log("server.js exited."); | |
}); | |
server.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment