gpt4 book ai didi

python - 重新加载与重新启动 uWSGI 以激活代码更改

转载 作者:行者123 更新时间:2023-12-03 17:24:37 25 4
gpt4 key购买 nike

读完uWSGI的documentation on reloading ,我的理解是,对于使用 lazy-apps 的应用程序, 写作 w uWSGI 的主 FIFO 应该触发所有 worker 的重启(从而激活 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
...
特别是 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
我正在运行版本 2.0.19.1 uWSGI。

最佳答案

我只知道 uWSGI 存在,但我注意到这里有一个错误:

ExecReload=/bin/echo 'w' > /run/myservice/masterfifo
手册页 explains the problem :

This syntax is inspired by shell syntax, but only the meta-charactersand expansions described in the following paragraphs are understood,and the expansion of variables is different. Specifically, redirectionusing "<", "<<", ">", and ">>", pipes using "|", running programs inthe background using "&", and other elements of shell syntax are notsupported.


换句话说,没有发生重定向并且 echo将简单地接收 3 个要打印的参数: char w , 字符 >和字符串 /run/myservice/masterfifo .
试试这个:
ExecReload=/bin/sh -c '/bin/echo w > /run/myservice/masterfifo'

关于python - 重新加载与重新启动 uWSGI 以激活代码更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67124732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com