Upboard

First we need to download:

$ sudo npm install -g pm2

* The -g option tells npm to install the module globally, so that it's available system-wide.

PM2 is simple and easy to use.

Start Application

The first thing you will want to do is use thepm2 startcommand to run your application, amikoo.upboard, in the background:

pm2 start amikoo.upboard

This also adds your application to PM2's process list, which is outputted every time you start an application:

Output
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2] Starting 
amikoo.upboard
 in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid  │ status │ restart │ uptime │ memory      │ watching │
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────────────┼──────────┤

amikoo
    │ 0  │ fork │ 3524 │ online │ 0       │ 0s     │ 21.566 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────────────┴──────────┘
 Use `pm2 show 
<
id|name
>
` to get more details about an app

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.

Thestartupsubcommand generates and configures a startup script to launch PM2 and its managed processes on server boots:

$ pm2 startup systemd

The last line of the resulting output will include a command that you must run with superuser privileges:

Output
[PM2] Init System found: systemd
[PM2] You have to run this command as root. Execute the following command:

sudo env PATH=$PATH:/usr/bin /usr/lib
ode_modules/pm2/bin/pm2 startup systemd -u norman --hp /home/norman

Run the command that was generated (similar to the highlighted output above, but with your username instead ofsammy) to set PM2 up to start on boot (use the command from your own output):

$ sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u norman --hp /home/norman

This will create a systemdunitwhich runspm2for your user on boot. Thispm2instance, in turn, runshello.js. You can check the status of the systemd unit withsystemctl:

systemctl status pm2-norman

Last updated

Was this helpful?