Skip to content

Instantly share code, notes, and snippets.

@dylants
Last active October 8, 2018 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylants/6133762 to your computer and use it in GitHub Desktop.
Save dylants/6133762 to your computer and use it in GitHub Desktop.
upstart config file for running node.js on a linux machine. This uses nodemon to allow file changes when pulled from git. This also specifies the NODE_ENV environment variable as "production" which would trigger the app to production mode (as opposed to development). Remove the environment variable if development environment is desired.
#!upstart
description "nodemon server for myapp"
author "ubuntu"
start on startup
stop on shutdown
script
export HOME="/home/ubuntu/git/myapp"
echo $$ > /var/run/myapp.pid
cd $HOME
exec sudo -u ubuntu NODE_ENV=production PORT=3000 /usr/bin/nodemon app.js >> /var/log/myapp.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/myapp.sys.log
end script
pre-stop script
rm /var/run/myapp.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/myapp.sys.log
end script
@dylants
Copy link
Author

dylants commented Aug 1, 2013

http://howtonode.org/deploying-node-upstart-monit

Location: /etc/init/myapp.conf

Start/Stop:
sudo service myapp start
sudo service myapp stop

Logs:
/var/log/myapp.sys.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment