Running Ghost as a Service on Ubuntu

I find that running certain things as a service on my VPS is a faster way to admin apps (i.e., start, stop, etc.) from the command line. I ran across a configuration online that worked well, so I thought I'd share.

At the Bash prompt:

sudo vi /etc/init/ghost.conf  

Place this text in the file:

 description "Ghost Blog"
 author "Your Name"
 # Start the service after everything loaded
 start on (local-filesystems and net-device-up IFACE=eth0)
 stop on shutdown
 # Automatically restart service
 respawn limit 99 5
     # Navigate to your app directory
     cd /path/to/ghost/

     # Run the script with Node.js and output to a log
     exec /usr/local/bin/npm start /path/to/ghost/ 2>&1 >> /var/log/ghost.log
 end script

Then, save your work (wq).

Now you can run the following from your Ubuntu command line:

service ghost <start|stop|status|restart>  

For you masochists, /etc/init.d will also work.

Now you don't have to mess with running npm start --production in the background. The best part about using this config file is that should Ghost crash, it will automatically restart itself.

Happy Ghosting!