Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Last active December 20, 2015 00:09
Show Gist options
  • Save jfromaniello/6039369 to your computer and use it in GitHub Desktop.
Save jfromaniello/6039369 to your computer and use it in GitHub Desktop.

This is an example upstart script to start a node.js application.

Install the node application as sudo npm install -g github url or tarball

This file goes to /etc/init/my-node-service. To manually start the service use:

sudo service my-node-service start

To stop

sudo service my-node-service stop

To restart

sudo service my-node-service restart

The service will be automatically started on reboot.

I usually create one user for service (in this case my-node-service-user).

The stdout and stderr is redirected to /var/log/my-node-service.log

Use tail -f /var/log/my-node-service.log to follow live logs.

Configure logrotate to rotate these logs periodically.

Another hint, I normally put my configuration in: /etc/my-node-service.json.

This is the most standard way linux daemon works, and the paths are very standard.

description "my-node-service"
author "I"
setuid my-node-service-user
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
respawn
respawn limit 15 5
script
exec >>/var/log/$UPSTART_JOB.log 2>&1
echo starting\ $UPSTART_JOB\ `date`
cd /usr/local/lib/node_modules/my-node-service/
NODE_ENV=production npm start
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment