How to Create a Start/Stop Script for your Ghost

Updated on Jul 13, 2018

In this tutorial we will show you how to create a simple start up script for your Ghost blog and configure your Ghost installation to start on server boot. Additionally, we will use Forever to monitor the Ghost process to make sure that it runs constantly and does not exit unexpectedly.

First, we will need to install Forever on your server. In case you have not already done this, please following our tutorial on How to install and use Forever with Ghost.

Next, lets create a simple bash script to start your Ghost process upon execution. You can simply copy and paste the following code example into a file called ghost-start.sh:

#!/bin/bash
export PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
cd /var/www/ghost
export NODE_ENV=production
NODE_ENV=production /usr/local/bin/forever -a -l /var/log/ghost start --sourceDir /var/www/ghost index.js

Please make sure that the above paths are correct and replace any paths that do not match your local Ghost installation. For example, you might need to change the /var/www/ghost and /var/log/ghost if you have your Ghost installed into a different directory or if you would like to have your Ghost input/output log stored under a different directory. When you are ready simply save the file and exit the text editor.

If you give executable permissions to your file (executing chmod 755 ghost-start.sh should be sufficient) you should be able to run the script and start your Ghost blog now.

Now, let's make sure that your Ghost blog starts upon server reboot. There are different ways to achieve this but the simplest one is to use your operation system cron tab. To achieve this, simply edit your crontab and add the following line:

@reboot /usr/local/bin/ghost-start.sh

Make sure to change the path to your ghost-start.sh script to match your server actual path to the script. You can access your user crontab using the following command:

crontab -e

which will open your use crontab with the default text editor for you to input the needed line.

On this page...

    Ghost Hosting

    • Free Ghost Installation
    • 24/7 Ghost Support
    • Hack-free Protection
    • Fast SSD Storage
    • Free Domain Transfer
    • Free Ghost Transfer
    • Immediate Activation
    • Free Cloudflare CDN
    View More