NodeJs - unable to kill process

Viewed 7632

I am working on a nodeJs project using PM2 for production. I manged to start a PM2 process to launch my nodeJs server.

I'm facing a strange behavior now : when I stop PM2 process via pm2 stop all I notice that my web app is still running.

After inspecting my port via

lsof -i:3000

I got :

COMMAND    PID     USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
node\x20/ 8239 user1   11u  IPv6 183534091      0t0  TCP *:3002 (LISTEN)
node\x20/ 8239 user1   18u  IPv6 183535847      0t0  TCP server.isymfony.net:3002->server.isymfony.net:51032 (ESTABLISHED)
node\x20/ 8239 user1   20u  IPv6 183526338      0t0  TCP server.isymfony.net:3002->server.isymfony.net:51036 (ESTABLISHED)

as you can see I found 3 processes with the same PID running and when I kill it using

kill -9 PROCESS_ID

then re-check I found it doesn't killed.

which mean when I restart my server via PM2 it will got an error because the port 3000 is in use.

Any suggestion about how to kill it or why I got this behavior ?

3 Answers

Try switching to root and then killing and restarting your pm2 process:

sudo -i -u root

pm2 kill

pm2 start [my server file]

If you've set up pm2 to run automatically with root permissions, you won't be able to kill or replace that process without root access. You could also use the sudo command to kill the process, instead of switching to root.

You might have multiple pm2 processed running.

Check with ps ax | grep pm2, kill all of them by hand with kill <PID> and then try starting clean again.

list processes with ps aux | grep God and kill all process IDs

Related