How to setup pm2 to automatically start after reboot?

$ pm2 start
$ pm2 save
$ pm2 startup

You will see something like the following after you run the last command:

[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/local/lib/nodejs/node-v12.18.0-linux-x64/bin /usr/local/lib/nodejs/node-v12.18.0-linux-x64/lib/node_modules/pm2/bin/pm2 startup systemd -u shukebeta --hp /home/shukebeta

copy the sudo line & paste it on your command line then press Enter! You have done.

Here's a sample pm2.config.json for a project.

{
  "apps" : [{
    "name": "tracking-system",
    "script": "app.js",
    "watch": ".",
    "exec_mode" : "cluster",
    "instances"  : 4,
    "exec_mode"  : "cluster",
    "autorestart": true
  } ]
}

Comments

  1. Markdown is allowed. HTML tags allowed: <strong>, <em>, <blockquote>, <code>, <pre>, <a>.