by using upstart
you'll be able stop using forever
for your node process management. upstart has mechanisms for ensuring your process is started/stopped/restarted in the event of a failure (or nearly any other event for that matter)
here's a modified version of your upstart script that uses upstart's respawn
directive to handle restarting your process if it crashes:
description "Start the node process with Upstart" author "you" # use if your process is going to fork *once* # expect fork # use if your process is going to fork *twice* # exepect daemon # respawn the process indefinitely # (ie. disregard the number of times it crashed # during a given interval and continuously # restart the process) respawn respawn limit unlimited setuid admin # ensures the process is only started once we have # filesystem access and an ethernet interface other # than loopback is available (ie. internet conn) # if your node process doesn't require net connectivity # just remove the `and net-device-up...` start on (local-filesystem and net-device-up IFACE!=lo) stop on shutdown # chdir sets the directory for all script blocks # (pre/post/errethang) chdir "/path/to/your/app" script # we're already in /path/to/your/app cause of `chdir` echo "app is starting" /usr/local/bin/node app.js 2>&1 > app.log end script pre-stop script echo "app is about to stop" end script
finally, to be certain that there are no syntax errors in your service conf, you can use init-checkconf /etc/init/myapp.conf
.
my main source of reference for upstart is here. this document is a bit heavyweight, though. and it's hard to discern real world usage from some of the examples.