Linux Server setup

Process manager PM2

In this chapter, we will install the PM2 process manager.

A process manager simplifies the starting and stopping of, for example, Node.js or Python applications.


Install PM2

Install PM2 with apt and an installation script:


__$ apt update && apt install sudo curl && curl -sL https://raw.githubusercontent.com/Unitech/pm2/master/packager/setup.deb.sh | sudo -E bash -
 

Or if npm is already installed:


__$ npm install pm2 -g
 

PM2 CLI Post-install autocomplete:


__$ pm2 completion install
 

Standard commands to PM2

PM2 process list


__$ pm2 list
 

PM2 monitoring


__$ pm2 monit
 

Start PM2 process


__$ pm2 start [start-file.ext]
 

Show trailing logs


__$ pm2 logs
 

Empty all log files


__$ pm2 flush
 

Restart PM2 process


__$ pm2 reload [ID]
 

Restart all PM2 processes


__$ pm2 reload all
 

Stop PM2 process


__$ pm2 stop [ID]
 

Stop all PM2 processes


__$ pm2 stop all
 

Delete PM2 process


__$ pm2 delete [ID]
 

Delete all PM2 processes


__$ pm2 delete all