当前在python环境下的flask应用程序正在运行,并且在命令(flask_api) ubuntu@ip:~/f_script$ gunicorn app:app
后可以从Internet访问
[2020-04-05 23:59:41 +0000] [1498] [INFO] Starting gunicorn 20.0.4
[2020-04-05 23:59:41 +0000] [1498] [INFO] Listening at: http://127.0.0.1:8000 (1498)
[2020-04-05 23:59:41 +0000] [1498] [INFO] Using worker: sync
[2020-04-05 23:59:41 +0000] [1501] [INFO] Booting worker with pid: 1501
我正在尝试将flaskapp设置为服务器中的服务,因为它是准备好的文件,但是无法启动该服务。
# /etc/systemd/system/gunicorn.service
[Unit]
Description=Gunicorn service
After=network.target
[Service]
User=ubuntu
Group=ubuntu
WorkDirectory=/home/ubuntu/f_script
ExecStart=/home/ubuntu/flask_api/bin/gunicorn --workers 2 --bin unix:flaskapp.sock -m 007 app:app
我决定从
设置ubuntuubuntu : ubuntu adm dialout cdrom floppy sudo audio dip video plugdev lxd netdev
WorkDirectory=/home/ubuntu/f_script
是app.py所在的位置。
但是,在配置,重新启动并检查状态后,它没有显示出来,并且错误为code=exited, status=1/FAILURE
~$ sudo service gunicorn status
● gunicorn.service - Gunicorn service
Loaded: loaded (/etc/systemd/system/gunicorn.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2020-04-05 22:13:04 UTC; 1h 28min ago
Process: 735 ExecStart=/home/ubuntu/flask_api/bin/gunicorn --workers 2 --bin unix:flaskapp.sock -m 007 app:app (code=exited, status=1/FAILURE)
Main PID: 735 (code=exited, status=1/FAILURE)
Apr 05 22:12:58 ip-systemd[1]: Started Gunicorn service.
Apr 05 22:12:59 ip-gunicorn[735]: [2020-04-05 22:12:59 +0000] [735] [INFO] Starting gunicorn 20.0.4
Apr 05 22:12:59 ip-gunicorn[735]: [2020-04-05 22:12:59 +0000] [735] [ERROR] Retrying in 1 second.
Apr 05 22:13:00 ip-gunicorn[735]: [2020-04-05 22:13:00 +0000] [735] [ERROR] Retrying in 1 second.
Apr 05 22:13:01 ip-gunicorn[735]: [2020-04-05 22:13:01 +0000] [735] [ERROR] Retrying in 1 second.
Apr 05 22:13:02 ip-gunicorn[735]: [2020-04-05 22:13:02 +0000] [735] [ERROR] Retrying in 1 second.
Apr 05 22:13:03 ip-gunicorn[735]: [2020-04-05 22:13:03 +0000] [735] [ERROR] Retrying in 1 second.
Apr 05 22:13:04 ip-gunicorn[735]: [2020-04-05 22:13:04 +0000] [735] [ERROR] Can't connect to flaskapp.sock
Apr 05 22:13:04 ip-systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Apr 05 22:13:04 ip-systemd[1]: gunicorn.service: Failed with result 'exit-code'.
~$
请一些提示来解决它。