【发布时间】:2017-02-05 12:03:36
【问题描述】:
我正在关注 this document 为我的 gunicorn 服务器设置 Systemd 套接字和服务。
- Systemd 以
www-data启动 gunicorn - gunicorn forks 自身(默认行为)
- 服务器用
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 -
【问题讨论】:
-
我现在放弃并停止使用 gunicorn。不过总有一天我需要解决这个问题,所以如果有人有任何想法,请告诉我!
-
我今天整天都有同样的问题。我按照这个文件(类似于你指出的那个)到了这封信:docs.gunicorn.org/en/stable/deploy.html (._.) Sigh。
标签: python subprocess gunicorn systemd