After reading the uWSGI's documentation on reloading, my understanding was that, for an app that uses lazy-apps
, writing w
to uWSGI's master FIFO should trigger a restart of all workers (and hence activate changes in the Python code).
However, that doesn't seem to work for me. I need to restart the systemd
service (systemctl restart myservice
) for code changes to take effect. Am I misunderstanding the documentation, or is there an issue with my setup?
My myservice.service
file looks like this:
...
ExecStart=/usr/lib/myservice/virtualenv/bin/uwsgi --ini /etc/myservice/uwsgi.ini
ExecReload=/bin/echo 'w' > /run/myservice/masterfifo
ExecStop=/bin/kill -INT $MAINPID
...
In particular, systemctl reload myservice
should write w
to the master FIFO. I can see from the logs in systemctl status myservice
that the reload was executed, but the responses to HTTP requests tell me that the old code is still active.
My /etc/myservice/uwsgi.ini
like this:
[uwsgi]
processes = 16
procname-master = myservice
master-fifo = /run/myservice/masterfifo
touch-chain-reload
listen = 128
thunder-lock
reload-on-as = 4096
limit-as = 8192
max-requests = 2000
; termination options
vacuum
die-on-term
; application
chdir = /usr/lib/myservice
virtualenv = /usr/lib/myservice/virtualenv
module = myservice.uwsgi
callable = app
master
need-app
enable-threads
lazy = True
lazy-apps = True
; logging
logto = /var/log/myservice/uwsgi.log
log-maxsize = 5242880
logdate = [%%Y/%%m/%%d %%H:%%M:%%S]
disable-logging
; stats server
stats-server = :8201
memory-report
; unix socket config (nginx->uwsgi)
socket = /run/myservice/myservice.sock
chown-socket = api
chmod-socket = 660
I'm running version 2.0.19.1
of uWSGI.
If you change uwsgi systemd service file, reload the daemon and restart the process by typing: sudo systemctl daemon-reload. sudo systemctl restart uwsgi.
Remember: lazy-apps is different from lazy, the first one only instructs uWSGI to load the application one time per worker, while the second is more invasive (and generally discouraged) as it changes a lot of internal defaults.
uwsgi (all lowercase) is the native binary protocol that uWSGI uses to communicate with other servers. uWSGI is often used for serving Python web applications in conjunction with web servers such as Cherokee and Nginx, which offer direct support for uWSGI's native uwsgi protocol.
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.
If you have started uwsgi with the --touch-reload=/path/to/special/file/usually/the.ini option, reloading your uWSGI is a simple matter of touch reloading that file with.
For instance, if we added/removed any settings from visual studio code or installed/uninstalled the any of the extension from visual studio code in the market place, if some times the changes not reflected so we need to forcefully to restart/reload the visual studio code. Steps 1: Go to Command Palette. Step 2: Type as “Developer: Reload Window”.
The main trick for avoiding it is: not closing the file descriptors mapped to the uWSGI daemon addresses and abusing the Unix fork () behaviour (read: file descriptors are inherited by default) to exec () the uwsgi binary again.
We have seen that holding the uWSGI sockets alive allows the proxy webserver to enqueue requests without spitting out errors to the clients. This is true only if your app restarts fast, and, sadly, this may not always happen.
All I know about uWSGI is that it exists, but I noticed a mistake here:
ExecReload=/bin/echo 'w' > /run/myservice/masterfifo
The man page explains the problem:
This syntax is inspired by shell syntax, but only the meta-characters and expansions described in the following paragraphs are understood, and the expansion of variables is different. Specifically, redirection using "<", "<<", ">", and ">>", pipes using "|", running programs in the background using "&", and other elements of shell syntax are not supported.
In other words, no redirection is taking place and echo
will simply receive 3 arguments to print: char w
, char >
and the string /run/myservice/masterfifo
.
Try this instead:
ExecReload=/bin/sh -c '/bin/echo w > /run/myservice/masterfifo'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With