๐Ÿš€ PM2 Persistence Guide


Here is a concise “Cheat Sheet” you can save to a notes file. These three steps are all you need to make sure your apps come back to life after a server reboot.


(Post-Reboot Autorestart)

Follow these steps after your app is already running in pm2 list.

1. Generate the Link

Tell PM2 to figure out your system’s startup requirements:

Bash

pm2 startup

2. Lock it in (The “Copy-Paste” Step)

PM2 will give you a specific command starting with sudo. Copy that entire line and run it. > This creates the system service that triggers PM2 on boot.

3. Save the Snapshot

Tell PM2 to remember exactly what is currently running so it can relaunch them later:

Bash

pm2 save

๐Ÿ’ก Quick Reference Commands

  • Update the list: If you add a new app later, just run pm2 save again to update the “snapshot.”
  • Remove startup: If you want to stop PM2 from starting on boot: pm2 unstartup.
  • Check Status: pm2 status (or pm2 list).

Note: If you ever update Node.js or PM2 itself, it is a good idea to run pm2 startup -u $(whoami) again to refresh the script paths.


Leave a Reply

Your email address will not be published. Required fields are marked *