Skip to content

Instantly share code, notes, and snippets.

@meowgorithm
Created November 25, 2013 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meowgorithm/7642419 to your computer and use it in GitHub Desktop.
Save meowgorithm/7642419 to your computer and use it in GitHub Desktop.
Node.js Upstart template for Ubuntu. Variables are as follows: PROJECT_PATH: Path to the directory of the Node.js script. PROJECT_NAME: Name to prepend to process and log files. ENGINE: "node" or "coffee". SERVER_SCRIPT_PATH: Path to the server script, i.e. `/var/www/project/server.js` or `/var/www/project/server.coffee`.
description "node.js server"
author "hi-res"
start on (local-filesystems and net-device-up)
stop on shutdown
respawn
script
export HOME="{{ PROJECT_PATH }}"
export NODE_ENV="production"
# Note that ENGINE below may be either 'node' or 'coffee' for JavaScript
# or CoffeeScript, respectively
echo $$ > /var/run/{{ PROJECT_NAME }}.pid
exec sudo -u www-data /usr/bin/env {{ ENGINE }} {{ SERVER_SCRIPT_PATH }} >> /var/log/{{ PROJECT_NAME }}.sys.log 2>&1
end script
pre-start script
# Date format same as (new Date()).toISOString() for consistency
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/{{ PROJECT_NAME }}.sys.log
end script
pre-stop script
rm /var/run/{{ PROJECT_NAME }}.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/{{ PROJECT_NAME }}.sys.log
end script
# vim:ft=upstart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment