繁体   English   中英

无法在 Centos 7 服务器上使用 systemd 将 flask 应用程序作为服务运行

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

我可以像这样在 virtualenv /web_services/flask_api/flask_api中运行 flask 应用程序:

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

但是,当我尝试将其作为服务运行时,它不起作用。 这是我创建.service配置文件的帖子:

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 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM