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?

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/ --bind --reload myproject.asgi.application

And graceful restart with the code:

cat /var/run/ | xargs kill -HUP

If you use docker, you can use the code:

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