PM2 can generate startup scripts and configure them in order to keep your process list intact across expected or unexpected machine restarts.
Make sure you upgrade to PM2 > 2.2.x
To get the automatically-configured startup script for your machine you need to type this command:
# Detect available init system, generate configuration and enable startup system $ pm2 startup
You can specify the platform you use yourself if you want to (where platform can be either one of cited above):
$ pm2 startup [platform]
The output of this command may be a recommendation of the line to copy/paste with all environment variables and options configured for you.
[PM2] You have to run this command as root. Execute the following command:
sudo su -c "env PATH=$PATH:/home/unitech/.nvm/versions/node/v4.3/bin pm2 startup <distribution> -u <user> --hp <home-path>
Just copy/paste the line PM2 give you and the startup script will be configured for your OS.
Once you started all the applications you want to manage, to keep this list across expected/unexpected server restart, just type the command:
$ pm2 save
Doing this will save the process list with their current environment into the dump file
Bring back previously saved processes (via pm2 save):
$ pm2 resurrect
$ pm2 unstartup
Above example let PM2 detect your platform, alternatively you can use another specified init system youself using :
$ pm2 unstartup [platform]
Let’s say you want the startup script to be executed under another user.
Just use the
-u <username> option and the
$ pm2 startup ubuntu -u www --hp /home/ubuntu