Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop gunicorn properly

I'm starting gunicorn with the Django command python manage.py run_gunicorn. How can I stop gunicorn properly?

Note: I have a semi-automated server deployment with fabric. Thus using something like ps aux | grep gunicorn to kill the process manually by pid is not an option.

like image 842
j7nn7k Avatar asked Jan 30 '13 13:01

j7nn7k


People also ask

How do I know if gunicorn is running?

You should receive the HTML output from your application in the terminal. This confirms that Gunicorn was started and able to serve your Django application. You can verify that the Gunicorn service is running by checking the status again: sudo systemctl status gunicorn.

How do you restart a gunicorn?

If you are running gunicorn on a port rather than a socket, you can find the process id (pid) of gunicorn using fuser command. Then force gunicorn to reload the code by sending a HUP signal.

Where is gunicorn PID file?

your pid file location is /run/gunicorn/gunicorn.

What is gunicorn command?

As a server runner, Gunicorn can serve your application using the commands from your framework, such as pserve or gearbox . To use Gunicorn with these commands, specify it as a server in your configuration file: [server:main] use = egg:gunicorn#main host = 127.0.0.1 port = 8080 workers = 3.


2 Answers

To see the processes is ps ax|grep gunicorn and to stop gunicorn_django is pkill gunicorn.

like image 65
Voislav Sauca Avatar answered Sep 17 '22 15:09

Voislav Sauca


One option would be to use Supervisor to manage Gunicorn.

Then again i don't see why you can't kill the process via Fabric. Assuming you let Gunicorn write a pid file you could easily read that file in a Fabric command.

Something like this should work:

run("kill `cat /path/to/your/file/gunicorn.pid`") 
like image 31
arie Avatar answered Sep 20 '22 15:09

arie