Peter Wilson
Peter Wilson

Reputation: 4319

NodeJs - unable to kill process

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 ?

Upvotes: 3

Views: 10389

Answers (3)

AAverin
AAverin

Reputation: 3042

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.

Upvotes: 1

Joe Walsh
Joe Walsh

Reputation: 210

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

Upvotes: 1

flannerykj
flannerykj

Reputation: 101

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.

Upvotes: 9

Related Questions