Skip to content

Instantly share code, notes, and snippets.

@lbdremy
Created December 24, 2012 12:17
Show Gist options
  • Save lbdremy/4369068 to your computer and use it in GitHub Desktop.
Save lbdremy/4369068 to your computer and use it in GitHub Desktop.
Template of an _upstart_ script for a node.js app.
description "your description"
author "your name <[email protected]>"
# Environment variables
env APP_CONFIG=/home/web/app/config.json
env APP_USER=myapp
env APP_SCRIPT=/home/web/app/index.js
env NODE_ENV=production
env PID_FILE=/var/run/app.pid
env STDERR_LOG_FILE=/var/log/app/stderr.log
env STDOUT_LOG_FILE=/var/log/app/stdout.log
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [016]
# If the process quits unexpectedly trigger a respawn
respawn
# respawn the job up to 3 times within a 30 second period.
# If the job exceeds these values, it will be stopped and
# marked as failed.
respawn limit 3 30
# Start the process
exec start-stop-daemon --start --chuid $APP_USER --make-pidfile --pidfile $PID_FILE --exec /usr/local/bin/node -- $APP_SCRIPT >> $STDOUT_LOG_FILE 2>> $STDERR_LOG_FILE
# Clean after stopping the process
post-stop script
rm $PID_FILE
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment