Updated on Jul 13, 2018
Despite the fact that it is not a must have feature to run Ghost, having Forever installed might be a good idea. Forever is a small and simple CLI tool for ensuring that a specific process is running and respawn it in case it exit unexpectedly. In short, it is a good way to keep your Ghost blog running.
If you already have Node.js installed on your system you can easily install Forever using the following command:
/usr/local/bin/npm install -g forever
When you have Forever installed, please stop your Ghost process so we can start it via Forever. This can be done using the following command:
/usr/local/bin/forever -a -l /var/log/ghost start --sourceDir /var/www/ghost index.js
You should replace the two underlined paths to match your current Ghost installation directory and the desired log folder for your Ghost process. When the above command is executed you should see the following output:
warn: --minUptime not set. Defaulting to: 1000ms warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms info: Forever processing file: index.js
And the following processes should be running on your server:
root 1609 1.8 2.2 661144 23052 ? Ssl 12:17 0:00 /usr/local/bin/node /usr/local/lib/node_modules/forever/bin/monitor index.js root 1611 5.2 6.7 984856 68524 ? Sl 12:17 0:02 \_ /usr/local/bin/node /var/www/ghost/index.js
This indicates that Forever is monitoring the Ghost processes and will restart it in case it exit.
Forever has a few simple usage options which can help you to manage your Forever monitored processes via the CLI: start, stop, stopall, list:
usage: forever [start | stop | stopall | list] [options] SCRIPT [script options] options: tart start SCRIPT as a daemon stop stop the daemon SCRIPT stopall stop all running forever scripts list list all running forever scripts
For example, to see your Ghost blog process please use 'forever list' command:
[[email protected] ghost]# forever list info: Forever processes running data: uid command script forever pid logfile uptime data:  1StY /usr/local/bin/node index.js 1635 1637 /var/log/ghost 0:0:0:6.162
To stop the process you can directly pass the Ghost uid to forever:
[[email protected] ghost]# forever stop 1StY info: Forever stopped process: data: uid command script forever pid logfile uptime  1StY /usr/local/bin/node index.js 1635 1637 /var/log/ghost 0:0:1:10.397
This will command Forever to terminate the process.