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
?
the one liner below, gets the job perfectly done:
kill -HUP `ps -C gunicorn fch -o pid | head -n 1`
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With