Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop a uWSGI server after starting it?

Tags:

uwsgi

pyramid

I have a Python pyramid application that I am running using uwsgi like so:

 sudo /finance/finance-env/bin/uwsgi --ini-paste-logged /finance/corefinance/production.ini

Once it's running and my window times out, I am unable to stop the server without rebooting the whole box. How do I stop the server?

like image 991
Jeremy T Avatar asked Aug 14 '16 01:08

Jeremy T


People also ask

Can I use uWSGI without nginx?

Can I then ditch NGINX? uWSGI could be used as a standalone web server in production, but that is not it's intentional use. It may sound odd, but uWSGI was always supposed to be a go-between a full-featured web server like NGINX and your Python files.

Is uWSGI a server?

uWSGI (source code), pronounced "mu wiz gee", is a Web Server Gateway Interface (WSGI) server implementation that is typically used to run Python web applications.

Which is better Gunicorn or uWSGI?

Gunicorn and uWSGI are primarily classified as "Web Servers" and "Web Server Interface" tools respectively. Gunicorn and uWSGI are both open source tools. Gunicorn with 5.96K GitHub stars and 1.12K forks on GitHub appears to be more popular than uWSGI with 2.5K GitHub stars and 541 GitHub forks.


2 Answers

You can kill uwsgi process using standard Linux commands:

killall uwsgi

or

# ps ax|grep uwsgi
12345
# kill -s QUIT 12345

The latter command allows you to do a graceful reload or immediately kill the whole stack depending on the signal you send.

The method you're using, however, is not normally used in production: normally you tell the OS to start your app on startup and to restart it if it crashes. Otherwise you're guaranteed a surprise one day at a least convenient time :) Uwsgi docs have examples of start scripts/jobs for Upstart/Systemd.

Also make sure you don't really run uwsgi as root - that sudo in the command makes me cringe, but I hope you have uid/gid options in your production.ini so Uwsgi changes the effective user on startup. Running a webserver as root is never a good idea.

like image 198
Sergey Avatar answered Sep 25 '22 21:09

Sergey


If you add a --pidfile arg to the start command

 sudo /finance/finance-env/bin/uwsgi --ini-paste-logged /finance/corefinance/production.ini --pidfile=/tmp/finance.pid

You can stop it with the following command

sudo /finance/finance-env/bin/uwsgi --stop /tmp/finance.pid

Also you can restart it with the following command

 sudo /finance/finance-env/bin/uwsgi --reload /tmp/finance.pid
like image 37
webjunkie Avatar answered Sep 22 '22 21:09

webjunkie