PM2 has the amazing ability to generate startup scripts and configure them. PM2 is also smart enough to save all your process list and to bring back all your processes on restart.
$ pm2 startup [ubuntu|centos|gentoo|systemd]
Once you have started the apps and want to keep them on server reboot do:
$ pm2 save
警告 It's tricky to make this feature work generically, so once PM2 has setup your startup script, reboot your server to make sure that PM2 has launched your apps!
Three types of startup scripts are available:
- SystemV init script (with the option
- OpenRC init script (with the option
- SystemD init script (with the
The startup options are using:
- ubuntu will use
updaterc.dand the script
- centos will use
chkconfigand the script
- gentoo will use
rc-updateand the script
- systemd will use
systemctland the script
Let's say you want the startup script to be executed under another user.
Just use the
-u <username> option !
$ pm2 startup ubuntu -u www
$ pm2 dump
$ pm2 [resurrect|save]