Created
January 24, 2014 01:19
-
-
Save tedyoung/8590327 to your computer and use it in GitHub Desktop.
Upstart script for restarting Node.js app when it exits unexpectedly
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
description "SitDown server running on node.js" | |
start on startup | |
stop on shutdown | |
# respawn (restart) automatically -- try only 10 times | |
respawn | |
respawn limit 10 10 | |
script | |
echo $$ > /var/run/sitdown.pid | |
exec /usr/local/bin/node /usr/local/sitdown-installed-here/app.js >> /var/log/sitdown.log 2>&1 | |
end script | |
pre-start script | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/sitdown.sys.log | |
echo "SitDown service (re)started at `date +"%F %T.%N"`" | mail -s "SitDown Service Started" name@example.com | |
end script | |
pre-stop script | |
rm /var/run/sitdown.pid | |
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/sitdown.sys.log | |
echo "SitDown service stopped at `date +"%F %T.%N"`" | mail -s "SitDown Service Stopped" name@example.com | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to http://howtonode.org/deploying-node-upstart-monit and http://kvz.io/blog/2009/12/15/run-nodejs-as-a-service-on-ubuntu-karmic/ and answers to questions on ServerFault: http://serverfault.com/questions/236925/how-can-i-receive-an-email-when-an-upstart-monitored-script-respawns?rq=1