If you are managing multiple apps or a high volume site, take a look at
Starting an uWSGI server is the role of the system administrator, like starting the Web server. It should not be the role of the Web server to start the uWSGI server – though you can also do that if it fits your architecture.
How to best start uWSGI services as boot depends on the operating system you use.
On modern systems the following should hold true. On “classic” operating systems you can use init.d/rc.d scripts, or tools such as Supervisor, Daemontools or inetd/xinetd.
|Ubuntu||Running uWSGI via Upstart (the official uwsgi package, available since Ubuntu 12.04 provides an init.d based solution. Read the README.)|
|Debian||Running uWSGI via Upstart|
You can instruct uWSGI to write the master process PID to a file with the pidfile option.
The uWSGI server responds to the following signals.
|SIGHUP||gracefully reload all the workers and the master process||–reload|
|SIGTERM||brutally reload all the workers and the master process|
|SIGINT||immediately kill the entire uWSGI stack||–stop|
|SIGQUIT||immediately kill the entire uWSGI stack|
|SIGUSR2||print worker status or wakeup the spooler|
|SIGURG||restore a snapshot|
|SIGTSTP||pause/suspend/resume an instance|
|SIGWINCH||wakeup a worker blocked in a syscall (internal use)|
When running with the master process mode, the uWSGI server can be gracefully restarted without closing the main sockets.
This functionality allows you patch/upgrade the uWSGI server without closing the connection with the web server and losing a single request.
When you send the SIGHUP to the master process it will try to gracefully stop all the workers, waiting for the completion of any currently running requests.
Then it closes all the eventually opened file descriptor not related to uWSGI.
Lastly, it binary patches (using execve()) the uWSGI process image with a new one, inheriting all of the previous file descriptors.
The server will know that it is a reloaded instance and will skip all the sockets initialization, reusing the previous ones.
Sending the SIGTERM signal will obtain the same result reload-wise but will not wait for the completion of running requests.
There are several ways to make uWSGI gracefully restart.
# using kill to send the signal kill -HUP `cat /tmp/project-master.pid` # or the convenience option --reload uwsgi --reload /tmp/project-master.pid # or if uwsgi was started with touch-reload=/tmp/somefile touch /tmp/somefile
Or from your application, in Python:
Or in Ruby,
If you have the uWSGI process running in the foreground for some reason, you can just hit CTRL+C to kill it off.
When dealing with background processes, you’ll need to use the master pidfile again. The SIGINT signal will kill uWSGI.
kill -INT `cat /tmp/project-master.pid` # or for convenience... uwsgi --stop /tmp/project-master.pid