Install PM2

Install PM2

by John Vincent

Posted on March 01, 2017

This is part of a series of discussions regarding Deploying to a Digital Ocean Droplet. For more details, please see Overview of website

Install PM2

Use PM2, a production process manager for Node applications with a built-in load balancer.

Shutdown Ghost. Ensure Ghost is shutdown before proceeding.

Install PM2

sudo npm install pm2 -g
pm2 -v

Start Ghost in Production

cd /var/www/ghost
NODE_ENV=production pm2 start index.js --name ghost

verify is running:

Start Ghost - local server

cd /var/www/ghost
pm2 start index.js

Change Ghost Blog

If make a change to your blog, you must restart:

pm2 restart all

Useful PM2 commands

pm2 list

pm2 stop <process-id>
pm2 stop all

pm2 restart <process-id>
pm2 restart all

pm2 delete <process-id>

pm2 describe <process-id>

pm2 monit

pm2 logs APP-NAME

pm2 flush

pm2 reloadLogs

PM2 Logs


Start Ghost on System Startup

PM2 will restart processes if they crash but cannot start itself.

Thus, need to start PM2 on system boot.

Useful reference

To get the automatically-configured startup script:

pm2 startup
[PM2] Init System found: systemd
[PM2] You have to run this command as root. Execute the following command:
sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u jv --hp /home/jv

[PM2] Freeze a process list on reboot via:
$ pm2 save

[PM2] Remove init script via:
$ pm2 unstartup systemd

Execute the suggested command:

sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u jv --hp /home/jv

Check status of systemd unit:

systemctl status pm2