I am using pm2 to start a nodejs service on Ubunutu 22.04.
The service is: /srv/goyard_print/nodejs/index.js.
I used pm2 to start the service and to configure it to automatically restart when necessary:
pm2 start /srv/goyard_print/nodejs/index.js
pm2 save
pm2 startup
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u goyard --hp /home/goyard
Note: the last line is the response from pm2 startup, copied and pasted into the command line.
All is good with this. The nodejs service is running, and even if I reboot my system, the service is launched as part of the boot process.
Now I want to shut down the nodejs process - not only to kill it, but also to prevent it from launching at boot-time.
I've tried the following:
pm2 unstartup
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 unstartup systemd -u goyard --hp /home/goyard
...and I've tried:
systemctl disable pm2-goyard.service
Both of these attempts appear to work if you ask their respective systems the status.
pm2 says it has no processes:
goyard@GoYard-BOXER-6404:~/Code$ pm2 ps
┌────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
└────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
systemd says the pm2-goyard service is disabled:
goyard@GoYard-BOXER-6404:~$ systemctl status pm2-goyard
○ pm2-goyard.service - PM2 process manager
Loaded: loaded (/etc/systemd/system/pm2-goyard.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: https://pm2.keymetrics.io/
But... the process is actually still running...
goyard@GoYard-BOXER-6404:~/Code$ ps -eo pid,ppid,lstart,cmd:140 | grep "PPID\|\<890\>\|index.js"
PID PPID STARTED CMD
890 1 Thu Dec 7 11:47:35 2023 PM2 v5.3.0: God Daemon (/root/.pm2)
2785 890 Thu Dec 7 13:16:10 2023 node /srv/goyard_print/nodejs/index.js
... and ps says the index.js process was launched by the "PM2 v5.3.0 God Daemon"
If I simply try to kill the process with:
sudo kill -9 2785
It comes right back up, saying it was launched yet again by the "God Daemon."
Any clues how I can get PM2 to actually kill the this service and keep it from re-launching?