Keep Ghost Running with pm2
When installing Ghost manually on a VPS or your home machine, a problem people run into is how to keep Ghost running after their terminal session has ended. pm2 allows you to keep Ghost running indefinitely and is very easy to setup and use. Here are the steps to installing pm2
and using it with Ghost:
Note: These commands should be run from a non root user that is dedicated to running Ghost.
cd /path/to/ghost/folder
sudo npm install -g pm2
echo "export NODE_ENV=production" >> ~/.profile
source ~/.profile
pm2 kill
pm2 start index.js --name ghost
pm2 dump
sudo pm2 startup <centos|ubuntu|amazon>
In the last command you will need to set the start up mode based on your operating system. For example if you are running in Amazon then your command will be:
pm2 startup amazon
.
Once you have Ghost up and running with pm2
some other useful pm2
commands are:
pm2 status
pm2 stop <process ID>
pm2 monit
pm2 logs
As you can see in the screen shot below the pm2 status
command will allow you to see some useful status on your Ghost instance. Three useful things to note from the command will be the id
, Uptime
, and err logs
columns. These will be very valuable.
The pm2 logs
command will give you live output from your Ghost blog.
And the pm2 monit
command will give you life status on the memory footprint of Ghost.
If you want more information on pm2, here is a link to their GitHub page.