Skip to content

Instantly share code, notes, and snippets.

@metakeule
Created March 14, 2012 13:21
Show Gist options
  • Save metakeule/2036410 to your computer and use it in GitHub Desktop.
Save metakeule/2036410 to your computer and use it in GitHub Desktop.
node app as daemon with nvm, upstart and monit
# /etc/monit/monitrc (excerpt)
check process node-app with pidfile /var/run/node-app.pid
start program = "/sbin/start node-app" with timeout 5 seconds
stop program = "/sbin/stop node-app"
if failed port 3000 protocol HTTP
request /
with timeout 3 seconds
then restart
if cpu > 80% for 10 cycles then restart
if 3 restarts within 10 cycles then timeout
group server
# /etc/init/node-app.conf
description "node-app"
# used to be: start on startup
# until we found some mounts weren't ready yet while booting:
start on started mountall
stop on shutdown
# Automatically Respawn:
respawn
respawn limit 99 5
script
export HOME="/node-app"
echo $$ > /var/run/node-app.pid
exec sudo -u node /bin/bash -c 'source . ~/.nvm/nvm.sh && export NODE_ENV=production && exec /node-app/.nvm/v0.6.11/bin/node /node-app/app.js' >> /var/log/node-app.log 3>&1
end script
pre-start script
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting node-app" >> /var/log/node-app.log
end script
pre-stop script
rm /var/run/node-app.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping node-app" >> /var/log/node-app.log
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment