在Centos 7服务器上无法将flask应用作为服务运行。

问题描述 投票:0回答:1

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

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

但是,当我试着把它作为一个服务来运行的时候,它却没有工作。这里有一个帖子,我按照这个帖子创建了一个名为 .service 配置文件。

https:/blog.miguelgrinberg.compostrunning-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)

不知道我漏掉了什么,或者做错了什么。任何帮助将被感激...

python flask centos7 gunicorn systemd
1个回答
0
投票

通过修改,它得到了解决。

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

© www.soinside.com 2019 - 2024. All rights reserved.