The following isn't for mission-critical systems, but it's been working so well for us and is so simple that I thought I'd share. We use nodemon (
https://github.com/remy/nodemon) to start our node server. It's just file watcher that restarts node if a source file changes, normally used for dev. It is much smaller and has fewer moving parts than forever. node-dev is a similar tool (
https://github.com/fgnass/node-dev) that many people like that does basically the same thing.
our startup script is something like this:
nohup nodemon <app> >>/var/log/app.log 2>&1 &
Then in our main app startup function, we have this charming little hack:
process.on('uncaughtException', function(err) {
console.error(err.stack||err)
if (serverStarted) {
fs.writeFileSync('./crash.js', '// App crashed ' + Date() + '\n\n' + err.stack)
}
process.exit(1)
})
The vast majority of our server crashes are due to bugs in our code, not external problems like hardware, and this works fine for those. If my job were on the line to keep the server alive no matter what I would figure out upstart or monit, but they both make my head hurt, and for the 90% case, this does the job.
Cheers!
-George