menu

Questions & Answers

How to gracefully restart django gunicorn?

I made a django application using docker.

Currently I send hup signal to gunicorn master process to restart.

If I simply send a hup signal, the workers are likely to restart without fully completing what they were doing.

Does gunicorn support graceful restart just by sending a hup signal to the master process?

If not, how can I gracefully restart the Gunicorn?

Comments:
2023-05-26 23:55:23
How are you sending the signal to the process? What command(s) do you run?
2023-05-26 23:55:23
@Iain Shelvington just docket exec <container name> sh -c "kill -hup $pid"
2023-05-26 23:55:23
Add that into your question
Answers(1) :

You can start gunicorn with the code:

gunicorn  --pid /var/run/gunicorn.pid --bind 0.0.0.0:80 --reload myproject.asgi.application

And graceful restart with the code:

cat /var/run/gunicorn.pid | xargs kill -HUP

If you use docker, you can use the code:

docker exec -it  my_container sh -c "cat /var/run/gunicorn.pid | xargs kill -HUP"