Flo*_*ker 8 python uwsgi systemd
在阅读了 uWSGI关于 reloading的文档后,我的理解是,对于使用 的应用程序lazy-apps
,写入w
uWSGI 的主 FIFO 应该触发所有工作程序的重新启动(从而激活 Python 代码中的更改)。
但是,这似乎对我不起作用。我需要重新启动systemd
服务 ( systemctl restart myservice
) 才能使代码更改生效。我误解了文档,还是我的设置有问题?
我的myservice.service
文件看起来像这样:
...
ExecStart=/usr/lib/myservice/virtualenv/bin/uwsgi --ini /etc/myservice/uwsgi.ini
ExecReload=/bin/echo 'w' > /run/myservice/masterfifo
ExecStop=/bin/kill -INT $MAINPID
...
Run Code Online (Sandbox Code Playgroud)
尤其是systemctl reload myservice
应该写到w
主设备的 FIFO。我可以从日志中systemctl status myservice
看到重新加载已执行,但对 HTTP 请求的响应告诉我旧代码仍然处于活动状态。
我/etc/myservice/uwsgi.ini
是这样的:
[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
Run Code Online (Sandbox Code Playgroud)
我正在运行2.0.19.1
uWSGI的版本。
我对 uWSGI 的了解就是它的存在,但我注意到这里有一个错误:
ExecReload=/bin/echo 'w' > /run/myservice/masterfifo
Run Code Online (Sandbox Code Playgroud)
手册页解释了这个问题:
该语法受到 shell 语法的启发,但仅理解以下段落中描述的元字符和扩展,并且变量的扩展有所不同。具体来说,不支持使用“<”、“<<”、“">”和“>>”的重定向、使用“|”的管道、使用“&”在后台运行程序以及 shell 语法的其他元素。
换句话说,没有发生重定向,echo
只会接收 3 个打印参数: char w
、 char>
和 string /run/myservice/masterfifo
。
试试这个:
ExecReload=/bin/sh -c '/bin/echo w > /run/myservice/masterfifo'
Run Code Online (Sandbox Code Playgroud)