systemd 设置service 的type为exec时,ExecStart 命令执行不成功 systemctl start 却操作成功

遇到的现象和发生背景

操作系统:ubuntu-20.04

查阅的文献资料地址:https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=

systemd service 中针对type=exec 的使用

文档中对type=exec 描述

Note that this means systemctl start command lines for exec services will report failure when the service's binary cannot be invoked successfully (for example because the selected User= doesn't exist, or the service binary is missing).

理解为服务的二进制文件不能被成功调用时,exec服务的systemctl start命令行将报告失败

以下为代码内容

flask_app.service


[Unit]
Description=Flask app

[Service]
Type=exec
PIDFile=/data/project/xhxf/log/flask_app.pid
WorkingDirectory=/data/project/xhxf/
ExecStart=/usr/bin/gunicorn -b localhost:7071  app:app
 
运行结果及详细报错内容

执行后发现 systemctl start 操作成功,systemctl status 查看任务,发现任务启动失败。理应systemctl start 就应该不成功。

img

来首先理解一下,Type=exec 的意思,我以前的笔记记录:

img

然后,要回过头来,要看你的执行程序了,如果你的二进制程序里面, fork() 与 execve() 的函数都执行成功,那就systemctl start 就会成功了,
所以,你若想研究这程序的启动底层,就需要你去研究 gunicorn 命令究竟如何调用来进一步分析了。这个超过我技能领域范畴,就比不了建议了,但肯定要去看他的启动调用函数是咋样的。