Skip to content

Instantly share code, notes, and snippets.

@iSaadSalman
Forked from jobsamuel/readme.md
Created March 10, 2016 17:29
Show Gist options
  • Save iSaadSalman/7e40a87c42b951e65eae to your computer and use it in GitHub Desktop.
Save iSaadSalman/7e40a87c42b951e65eae to your computer and use it in GitHub Desktop.
Run NodeJS as a Service on Ubuntu 14.04 LTS

Run NodeJS as a Service on Ubuntu 14.04 LTS

With Node you can write very fast JavaScript programs serverside. It's pretty easy to install Node, code your program, and run it. But > how do you make it run nicely in the background like a true server?

  • Go to /etc/init/
  • $ sudo vim yourapp.conf
  • Paste script.conf
  • $ sudo start yourapp
  • And when you wanna kill the process $ sudo stop yourapp

Reference

Thanks to [kvz.io] (http://kvz.io/blog/2009/12/15/run-nodejs-as-a-service-on-ubuntu-karmic/) for this!

description "node.js server"
author "Foo Bar"
# used to be: start on startup
# until we found some mounts weren't ready yet while booting
start on started mountall
stop on shutdown
# automatically respawn
respawn
respawn limit 99 5
script
export HOME="/root"
exec /usr//bin/nodejs /path/to/yourapp.js >> /var/log/node.log 2>&1
end script
post-start script
# optionally put a script here that will notifiy you node has (re)started
# /root/bin/hoptoad.sh "node.js has started!"
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment