As you can see, PM2 automatically assigns an App name (based on the filename, without the .js extension) and a PM2 id. PM2 also maintains other information, such as the PID of the process, its current status, and memory usage.
Applications that are running under PM2 will be restarted automatically if the application crashes or is killed, but an additional step needs to be taken to get the application to launch on system startup (boot or reboot). Luckily, PM2 provides an easy way to do this, the startup subcommand.
The startup subcommand generates and configures a startup script to launch PM2 and its managed processes on server boots. You must also specify the platform you are running on, which is ubuntu, in our case:
1
pm2 startup ubuntu
The last line of the resulting output will include a command (that must be run with superuser privileges) that you must run:
1 2 3 4
Output: [PM2] You have to run this command as root [PM2] Execute the following command : [PM2] sudo su -c "env PATH=$PATH:/opt/node/bin pm2 startup ubuntu -u sammy --hp /home/sammy"
Run the command that was generated (similar to the highlighted output above) to set PM2 up to start on boot (use the command from your own output):