无法 运行 Flask 应用程序作为 Centos 7 服务器上 systemd 的服务

Unable to run flask application as a service with systemd on Centos 7 server

我可以在 virtualenv /web_services/flask_api/flask_api 中 运行 flask app 像这样:

gunicorn --workers=4 --bind=localhost:8000 --log-level=error app:app

但是,当我尝试 运行 它作为一项服务时,它不起作用。这是我用来创建 .service 配置文件的 post:

https://blog.miguelgrinberg.com/post/running-a-flask-application-as-a-service-with-systemd

这是我的 web_service.service 文件的样子:

[Unit]
Description=Sample web service
After=network.target 

[Service]
User=aaa.bbb
WorkingDirectory=/web_services/flask_api/flask_api
ExecStart=/web_services/flask_api/flask_api/bin/gunicorn --workers=4 --bind=localhost:8000 --log-level=error web_service:app
Restart=always 

[Install]
WantedBy=multi-user.target

保存此文件后我做了:

$ sudo systemctl daemon-reload
$ sudo systemctl start web_service
$ sudo systemctl enable web_service

systemctl | grep running 未显示此 api。

在检查此服务的状态时,我得到了这个:

sudo systemctl status web_service
● web_service.service - Sample web service  
 Loaded: loaded (/etc/systemd/system/web_service.service; enabled; vendor preset: disabled)   
 Active: failed (Result: start-limit) since Mon 2020-06-01 16:15:15 EDT; 13s ago 
 Process: 1016 ExecStart=/web_services/flask_api/flask_api/bin/gunicorn --workers=4 --bind=localhost:8000 --log-level=error web_service:app (code=exited, status=1/FAILURE)
 Main PID: 1016 (code=exited, status=1/FAILURE)

不知道我在这里遗漏了什么或做错了什么。任何帮助将不胜感激..

它通过更改解决了:

ExecStart=/web_services/flask_api/flask_api/bin/gunicorn --workers=4 --bind=localhost:8000 --log-level=error web_service:app

ExecStart=/web_services/flask_api/flask_api/bin/gunicorn --workers=4 --bind=localhost:8000 --log-level=error app:app