pm2

pm2: start, startup, save, list, logs, monit and Cluster Mode

pm2 29,762 (github.com/Unitech/pm2 (https://github.com/Unitech/pm2 43,298 ), AGPL-3.0) is a Node.js 2,131 process manager whose "God daemon" starts programs, restarts them and collects their logs. Version 7.0.4 (24 August 2026) needs Node.js 18+, so Ubuntu 26.04 225 's Node 22.22.1 suffices: sudo apt install nodejs npm 2,036 , then sudo npm install -g pm2. --interpreter php runs PHP; worker.php logs one "job" every two seconds.

Start, crash, list, read logs, then survive rebootsShell
pm2 start worker.php --name queue-worker --interpreter php
kill -9 $(pm2 pid queue-worker); sleep 2         # simulate a crash
pm2 ls
pm2 logs queue-worker --lines 2 --nostream
pm2 startup                                       # prints the command to run as root
sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd \
  -u dev --hp /home/dev
pm2 save
systemctl is-enabled pm2-dev; systemctl is-active pm2-dev
Output
...
│ id │ name            │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼─────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ queue-worker    │ fork     │ 1    │ online    │ 0%       │ 36.0mb   │
...
0|queue-wo | [05:59:19] pid 15006 handled job 2
...
sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u dev --h
p /home/dev
...
[PM2] Successfully saved in /home/dev/.pm2/dump.pm2
enabled
inactive

The ↺ column counts restarts: pm2 replaced the killed worker. pm2 startup prints a root command, which writes pm2-dev.service (Type=forking, ExecStart=pm2 resurrect). pm2 save stores the list in dump.pm2 for resurrect to replay at boot; forget it and the server boots to an empty list. Note inactive: this daemon was started by hand, so systemd 142,543 owns it only from the next boot. After pm2 kill and sudo systemctl start pm2-dev, the worker came back inside the unit's cgroup.

pm2 monit is a live dashboard of CPU, memory and logs. -i 4 on a Node.js program starts cluster mode, four instances sharing one port via Node's cluster module; on the PHP worker, -i 2 gave two plain fork_mode copies. --max-memory-restart 200M recycles leaky workers; pm2 unstartup systemd undoes it.