When installing Ghost manually on a VPS or your home machine, a problem most people run into is how to keep Ghost running after their terminal session has ended. There are multiple ways to do this, the most popular way currently being forever.
pm2 is a great alternative to forever. 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.
sudo npm install -g pm2
echo "export NODE_ENV=production" >> ~/.profile
pm2 start index.js --name ghost
Once you have Ghost up and running with
pm2 some other useful
pm2 commands will be:
pm2 stop <process ID>
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
err logs columns. These will be very valuable.
pm2 logs command will give you live output from your Ghost blog.
pm2 monit command will give you life status on the memory footprint of Ghost.
Another great feature of
pm2 is the ability to create an init script which will deal with the situation of your server restarting. The popular forever process of keeping Ghost up and running does not have any built in way of dealing with a server restart, so I see this is a major advantage that
pm2 has over forever. The init script will start
pm2, which will start Ghost when your server starts up and then will continue to monitor it. To take advantage of this feature all you have to do is running the following command:
And then you should see
pm2 output something similar to this:
Adding system startup for /etc/init.d/pm2-init.sh ... /etc/rc0.d/K20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc1.d/K20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc6.d/K20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc2.d/S20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc3.d/S20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc4.d/S20pm2-init.sh -> ../init.d/pm2-init.sh /etc/rc5.d/S20pm2-init.sh -> ../init.d/pm2-init.sh
If you want more information on pm2, here is a link to their GitHub page.