PM2 can generate startup scripts and configure them in order to keep your process list intact across expected or unexpected machine restarts.
To get the automatically-configured startup script for your machine you need to type this command:
# Auto-detect platform $ pm2 startup # OR # Render startup-script for a specific platform, the [platform] could be one of: # ubuntu|centos|redhat|gentoo|systemd|darwin|amazon $ 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 this line 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
Warning We recommend you to double check that everything is working correctly by restarting your server.
Multiple types of startup scripts are available:
The distribution option after doing
pm2 startup <distribution> will use:
updaterc.dand the script
chkconfigand the script
rc-updateand the script
systemctland the script
launchdto load a specific
plistto resurrect processes after reboot
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
The environment variable
MAX_OPEN_FILE allows to change the maximum open file descriptor.
MAX_OPEN_FILE variable in /etc/default/pm2
Tool to verify startup applications (available on Ubuntu):
$ sudo apt-get install rcconf # Check for pm2 script related $ sudo rcconf
# Ubuntu $ sudo update-rc.d -f pm2-init.sh remove
Bring back previously saved processes (via pm2 save):
$ pm2 resurrect