How to kill the pm2 --no-daemon process

Viewed 124875

I'm using pm2 as the process manager of Node.js.

In many cases, I think I will run it as a daemon process, but if you use it locally as debugging, I think that there are times when you use the --no-daemon option.

How do I end the process when moving pm2 with this --no-daemon option?

8 Answers

You can view all processes which are registered with pm2 using

pm2 list

Assume the process you want to stop is named as processA using the below command will stop the processA:

pm2 stop processA

In case you want to delete the process than use the below command:

pm2 delete processA

In case you don't want to kill a particular process but pm2 itself using the command below:

pm2 kill

The right answer is pm2 kill

$pm2 kill
[PM2] [v] Modules Stopped
[PM2] Applying action deleteProcessId on app [all](ids: 0)
[PM2] hello ✓
[PM2] [v] All Applications Stopped
[PM2] [v] PM2 Daemon Stopped

Other solution will be to run pm2 delete all or pm2 stop all. Which will not kill pm2 process itself, but will cleanup internal pm2's process list.

First of all list all processes:

pm2 list

let suppose if your process is dev

pm2 stop dev

Now, delete the process

pm2 delete dev

after that process state became daemon.

If you want to kill that daemon process then run command

pm2 kill
sudo pkill -f pm2

This should kill all processes of pm2 in linux

One thing to add to the accepted answers. These commands only work for the current user. I had the same problem with a digitalocean droplet. I had logged in using "ubuntu" username, but I saw that the God Daemon is pointing to /home/nodejs/.pm2.

If this is the case, you need to switch to that user: sudo su nodejs And then run the pm2 kill commands from there.

Related