Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I restart gunicorn hup , i dont know masterpid or location of PID file

I want to restart a Django server which is running using gunicorn.

I know how to use gunicorn in my system. But now I need to restart a remote server which is not set up by me.

I don't know masterpid to restart the server how can I get the masterPID.

Usually I HUP gunicorn with sudo kill -s HUP masterpid.

I tried with ps aux|grep gunicorn

and I did not find the gunicorn.pid file anywhere.

How can I get the masterpid?

like image 843
RMK Avatar asked Nov 13 '14 06:11

RMK


2 Answers

the one liner below, gets the job perfectly done:

kill -HUP `ps -C gunicorn fch -o pid | head -n 1`

Explanation

pc -C gunicorn only lists the processes with gunicorn command, i.e., workers and master process. Workers are children of master as can be seen using ps -C gunicorn fc -o ppid,pid,cmd. We only need the pid of the master, therefore h flag is used to remove the first line which is PID text. Note that, f flag assures that master is printed above workers.

The correct procedure is to send HUP signal only to the master. In this way gunicorn is gracefully restarted, only the workers, not master, are recreated.

like image 153
rowman Avatar answered Sep 22 '22 00:09

rowman


You can run gunicorn with option '-p', so you can get the pid of the master process from the pid file. For example:

gunicorn -p app.pid your_app.wsgi.app

You can get the pid of the master by:

cat app.pid
like image 27
krizex Avatar answered Sep 22 '22 00:09

krizex