Running Ghost as a service

Once you have a ghost blog set up it's quite easy to get it running with the usual command:

npm start --production

However the blog will stop running as soon as you close your ssh session. To fix this you can add ghost as a service, which gives you further control over the blog and automates restarts should your server restart or node server crash.

To set this up first create a service file for it (where <blog_name> is your blog):

sudo vim /etc/init/<blog_name>-ghost.conf

Next, edit this file and add the following:
Be sure to replace <blog_name> and <path_to_blog> with your details

#/etc/init/<blog_name>ghost.conf
description "Ghost Blog"
author "Full Name"
# Start the service after everything loaded
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
# Automatically restart service
respawn
respawn limit 99 5
script
    # Navigate to your app directory
    cd /var/www/<path_to_blog>/public_html

    # Run the script with Node.js and output to a log
    export NODE_ENV=production
    exec /usr/local/bin/npm start /var/www/<path_to_blog>/public_html 2>&1 >> /var/www/<path_to_blog>/log/ghost.log
end script

Then control the service using:

sudo service ghost start
sudo service ghost stop
sudo service ghost restart
sudo service ghost status

All done!

Credit due to:

https://ghost.org/forum/using-ghost/453-stupid-question-how-do-i-keep-ghost-running/10/ http://ghost.pellegrom.me/installing-ghost-on-ubuntu/