2016-09-27 75 views
2

我正在關注this document以爲我的gunicorn服務器設置Systemd套接字和服務。Systemd +非根Gunicorn服務=已停用的子進程

  • Systemd開始gunicorn爲www-data
  • gunicorn叉本身(默認行爲)
  • 服務器開始與subprocess.Popen()
  • 子進程完成一個子沒有錯誤,但父母一直從p.poll()獲得無而不是退出代碼
  • 子過程結束失效

這裏的進程層次:

$ 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 - 
+1

我放棄了,現在停止使用gunicorn。我需要在某一天解決這個問題,所以如果有人有任何想法,請讓我知道! –

+0

我今天整天都有同樣的問題。我遵循這個文件(類似於你指出的那封):http://docs.gunicorn.org/en/stable/deploy.html(._。)感嘆。 –

回答

1

我今天碰到了同樣的問題上的CentOS-7。我最終忽略了this document中的指令,它指示使用/run/層次結構創建套接字 - 而我使用的是/tmp/。這工作。

請注意,我的PID文件仍位於/run/之下(這裏沒有問題)。

總之,不要將您的套接字放在/run/...下的某個位置,而應嘗試將它放在/tmp/...下的某個位置。它在我的工作CentOS-7系統