gpt4 book ai didi

python - Systemd + 非根 Gunicorn 服务 = 不存在的子进程

转载 作者:行者123 更新时间:2023-11-28 18:28:06 25 4
gpt4 key购买 nike

我正在关注 this document为我的 gunicorn 服务器设置 Systemd 套接字和服务。

  • Systemd 将 gunicorn 作为 www-data 启动
  • gunicorn fork 自身(默认行为)
  • 服务器用subprocess.Popen()启动一个子进程
  • 子进程没有错误地完成,但父进程一直从 p.poll() 获取 None 而不是退出代码
  • 子流程结束了

这是流程层次结构:

$ ps eauxf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
...
www-data 14170 0.0 0.2 65772 20452 ? Ss 10:57 0:00 /usr/bin/python /usr/bin/gunicorn digits.webapp:app --pid /run/digits/pid --config /usr/lib/python2.7/dist-packages/digits/gunicorn_config.py
www-data 14176 0.8 3.4 39592776 283124 ? Sl 10:57 0:05 \_ /usr/bin/python /usr/bin/gunicorn digits.webapp:app --pid /run/digits/pid --config /usr/lib/python2.7/dist-packages/digits/gunicorn_config.py
www-data 14346 5.0 0.0 0 0 ? Z 11:07 0:01 \_ [python] <defunct>

关键是:当我以 root 而不是 www-data 运行服务时,一切都按预期运行。子进程完成,父进程立即获得子进程的返回码。

/lib/systemd/system/digits.service

[Unit]
Description=DIGITS daemon
Requires=digits.socket
After=local-fs.target network.target
[Service]
PIDFile=/run/digits/pid
User=www-data
Group=www-data
Environment="DIGITS_JOBS_DIR=/var/lib/digits/jobs"
Environment="DIGITS_LOGFILE_FILENAME=/var/log/digits/digits.log"
ExecStart=/usr/bin/gunicorn digits.webapp:app \
--pid /run/digits/pid \
--config /usr/lib/python2.7/dist-packages/digits/gunicorn_config.py
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

/lib/systemd/system/digits.socket

[Unit]
Description=DIGITS socket
[Socket]
ListenStream=/run/digits/socket
ListenStream=0.0.0.0:34448
[Install]
WantedBy=sockets.target

/usr/lib/tmpfiles.d/digits.conf

d /run/digits 0755 www-data www-data -

最佳答案

我今天在 CentOS-7 上遇到了同样的问题。我终于通过忽略 this document 中的说明克服了它-- 这表示使用 /run/ 层次结构在其中创建套接字 -- 我改为使用 /tmp/。那行得通。

请注意,我的 PID 文件仍位于 /run/ 下(那里没有问题)。

总而言之,不要将套接字放在 /run/... 下面的某处,而是尝试将它放在 /tmp/... 下面的某处。它适用于 CentOS-7systemd

关于python - Systemd + 非根 Gunicorn 服务 = 不存在的子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39731727/

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