我无法启动Gunicorn即服务

时间:2020-03-26 14:11:09

标签: nginx webserver gunicorn wsgi

根据主题
https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04
我设法使用

手动启动了app.py
gunicorn --bind 0.0.0.0:5000 wsgi:app

但是当我尝试提供服务以自动运行Gunicorn时,我做不到。

我创建了/etc/systemd/system/telegram_bot.service:

[Unit]
Description=Gunicorn instance to serve telegram_bot
After=network.target

[Service]
User=victor
Group=www-data
WorkingDirectory=/home/victor/bot/bot/telegram_bot
Environment="PATH=/home/victor/bot/bot/env/bin"
ExecStart=/home/victor/bot/bot/env/bin/gunicorn --workers 3 --bind unix:app.sock -m 007 wsgi:app

[Install]
WantedBy=multi-user.target

态度:
-rw-r--r--。 1胜利者www-data 352 3月26日15:17 telegram_bot.service

项目结构:
/ home / victor /
----------------- bot /
--------------------- bot /
------------------------- env /
------------------------- telegram_bot /
-------------------------------------------app.py
-------------------------------------------wsgi.py

像该主题中的app.py和wsgi.py。
-rwxr-xr-x。 1 victor victor 162 Mar 25 14:26 app.py
-rwxr-xr-x。 1 victor victor 58 Mar 24 22:08 wsgi.py

命令后

sudo systemctl start telegram_bot

我收到消息:

● telegram_bot.service - Gunicorn instance to serve telegram_bot
   Loaded: loaded (/etc/systemd/system/telegram_bot.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2020-03-26 17:00:21 MSK; 6s ago
  Process: 17059 ExecStart=/home/victor/bot/bot/env/bin/gunicorn --workers 3 --bind unix:app.sock -m 007 wsgi:app (code=exited, status=203/EXEC)
 Main PID: 17059 (code=exited, status=203/EXEC)

Mar 26 17:00:21 CentOS7x64 systemd[1]: Started Gunicorn instance to serve telegram_bot.
Mar 26 17:00:21 CentOS7x64 systemd[1]: telegram_bot.service: main process exited, code=exited, status=203/EXEC
Mar 26 17:00:21 CentOS7x64 systemd[1]: Unit telegram_bot.service entered failed state.
Mar 26 17:00:21 CentOS7x64 systemd[1]: telegram_bot.service failed.

我浏览了journalctl并发现:

Mar 26 16:36:28 CentOS7x64 sudo[16665]:   victor : TTY=pts/0 ; PWD=/home/victor/bot/bot/telegram_bot ; USER=root ; COMMAND=/bin/systemctl start telegram_bot
Mar 26 16:36:28 CentOS7x64 sudo[16665]: pam_unix(sudo:session): session opened for user root by victor(uid=0)
Mar 26 16:36:28 CentOS7x64 polkitd[646]: Registered Authentication Agent for unix-process:16667:103892680 (system bus name :1.745 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Mar 26 16:36:28 CentOS7x64 systemd[1]: Started Gunicorn instance to serve telegram_bot.
Mar 26 16:36:28 CentOS7x64 sudo[16665]: pam_unix(sudo:session): session closed for user root
Mar 26 16:36:28 CentOS7x64 polkitd[646]: Unregistered Authentication Agent for unix-process:16667:103892680 (system bus name :1.745, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Mar 26 16:36:28 CentOS7x64 systemd[16673]: Failed at step EXEC spawning /home/victor/bot/bot/env/bin/gunicorn: Permission denied
Mar 26 16:36:28 CentOS7x64 systemd[1]: telegram_bot.service: main process exited, code=exited, status=203/EXEC
Mar 26 16:36:28 CentOS7x64 systemd[1]: Unit telegram_bot.service entered failed state.
Mar 26 16:36:28 CentOS7x64 systemd[1]: telegram_bot.service failed.

我一直在寻找解决方案两天。我错过了什么?
CentOS 7

0 个答案:

没有答案