系统服务有时会在启动时崩溃

时间:2019-08-22 12:58:34

标签: python flask centos7 gunicorn systemd

我尝试使用systemd启动Gunicorn服务器。

服务定义如下:

[Unit]
Description=Gunicorn instance to serve Flask application using gunicorn
After=network.target

[Service]
PIDFile=/home/username/application/app.pid
User=username
Group=nginx
WorkingDirectory=/home/username/application
Environment=PATH=/opt/venv/bin/
ExecStart=/opt/venv/bin/gunicorn --pid /home/username/application/app.pid --workers 3 --bind unix:socket.sock -m 007 app:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

问题在于,有时应用程序会在启动时崩溃,并在journalctl中显示以下消息

gunicorn[28376]: [2019-08-22 15:01:48 +0300] [28379] [INFO] Worker exiting (pid: 28379)
gunicorn[28376]: [2019-08-22 15:01:48 +0300] [28381] [INFO] Worker exiting (pid: 28381)
gunicorn[28376]: [2019-08-22 15:01:48 +0300] [28376] [INFO] Shutting down: Master
gunicorn[28376]: [2019-08-22 15:01:48 +0300] [28376] [INFO] Reason: Worker failed to boot.
systemd[1]: urzchat-dev.service: main process exited, code=exited, status=3/NOTIMPLEMENTED
systemd[1]: urzchat-dev.service: control process exited, code=exited status=1
systemd[1]: Unit urzchat-dev.service entered failed state.
systemd[1]: urzchat-dev.service failed.

大约在所有启动中发生这种情况。

告诉我,为什么会这样,以及如何解决?

1 个答案:

答案 0 :(得分:0)

Environment指令应作为字符串括起来:

Environment="PATH=/opt/venv/bin/"

此外,您可以在开始之前为网络连接到Internet添加条件:

After=network.target network-online.target
相关问题