Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot kill gunicorn processes

I am using a digitalocean ubuntu 14.04 vps. When I run

sudo lsof -i:9000

I get varying results such as

COMMAND    PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gunicorn 23148 django    5u  IPv4  51019      0t0  TCP localhost:9000 (LISTEN)

or

COMMAND    PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gunicorn 23174 django    5u  IPv4  51179      0t0  TCP localhost:9000 (LISTEN)
gunicorn 23175 django    5u  IPv4  51179      0t0  TCP localhost:9000 (LISTEN)

where the number of gunicorn processes varies from 0-4, even if I run lsof immediately after the previous attempt. Simply running

pkill gunicorn

is failing, I believe because the PIDs are constantly changing (as shown above). How can I kill these processes permanently? If it makes a difference, I am user "root", and do not have a login for user "django"

like image 240
David Avatar asked Sep 07 '26 13:09

David


1 Answers

lsof will only show the child processes which are actually binding to the port. You need to kill the master process. If you start gunicorn with the --pid option you can give it a filename to store the PID of that process in, then you can kill it directly; if not you can get it from ps|grep gunicorn.

Even better, as elethan suggests in the comments, set up gunicorn as a service using whatever process manager exists on your system - systemd, upstart, supervisor, or whatever - and use that to start and stop it.

like image 87
Daniel Roseman Avatar answered Sep 10 '26 05:09

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!