Systemd服务有时在启动时崩溃

2024-10-03 13:30:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用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/3。你知道吗

告诉我,为什么会这样,怎么解决?你知道吗


Tags: devinfoapphomebinapplicationserviceusername
1条回答
网友
1楼 · 发布于 2024-10-03 13:30:23

Environment指令应包含为字符串:

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

此外,您还可以在启动前为网络连接到internet添加一个条件:

After=network.target network-online.target

相关问题 更多 >