Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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/`.
description "node.js server"
author "hi-res"
start on (local-filesystems and net-device-up)
stop on shutdown
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
You can’t perform that action at this time.