Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gunicorn systemd service unable to start Python Flask WSGI app #3138

Open
potequity opened this issue Jan 13, 2024 · 1 comment
Open

Gunicorn systemd service unable to start Python Flask WSGI app #3138

potequity opened this issue Jan 13, 2024 · 1 comment

Comments

@potequity
Copy link

Hello,

I have written an app using Python 3.11 and Flask, which I integrated with Gunicorn v21.2.0. I'm able to launch the app using this command and access the web page successfully:
gunicorn --log-file ./guni.log --bind 0.0.0.0:5000 wsgi:app

My app directory structure is as follows:

/home/webadmin
|
| ---./webui
|
| ---./webuienv
| ---./app
| ---./wsgi.py
| ---./config.py

Next I tried to integrate my app with NGINX and Gunicorn with a systemd service listening on a Unix socket. I following the section for systemd in this article [https://docs.gunicorn.org/en/stable/deploy.html] and created the following gunicorn.socket and gunicorn.service files.

gunicorn.socket:
[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

SocketUser=webadmin
SocketGroup=nginx

[Install]
WantedBy=sockets.target

gunicorn.service:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
Type=notify

User=webadmin
Group=nginx
RuntimeDirectory=gunicorn
WorkingDirectory=/home/webadmin/webui
ExecStart=/home/webadmin/webui/webuienv/bin/gunicorn
--log-file=/var/log/gunicorn.log
wsgi:app
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=5
PrivateTmp=true

[Install]
WantedBy=multi-user.target

I did a 'systemctl daemon-reload' and tried to start the 'gunicorn.socket' service. While the 'gunicorn.socket' starts, the 'gunicorn.service' does not.
It shows these errors:

Jan 12 15:51:36 example gunicorn[2399]: [2024-01-12 15:51:36 -0800] [2399] [INFO] Worker exiting (pid: 2399)
Jan 12 15:51:37 example gunicorn[2398]: [2024-01-12 15:51:37 -0800] [2398] [ERROR] Worker (pid:2399) exited with code 3
Jan 12 15:51:37 example gunicorn[2398]: [2024-01-12 15:51:37 -0800] [2398] [ERROR] Shutting down: Master
Jan 12 15:51:37 example gunicorn[2398]: [2024-01-12 15:51:37 -0800] [2398] [ERROR] Reason: Worker failed to boot.
Jan 12 15:51:37 example systemd[1]: gunicorn.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Jan 12 15:51:37 example systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jan 12 15:51:37 example systemd[1]: gunicorn.service: Start request repeated too quickly.
Jan 12 15:51:37 example systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Jan 12 15:51:37 example systemd[1]: Failed to start gunicorn daemon.

I'm not sure why this is failing, I've checked the permissions of all the files and directories involved, I've reinstalled python and all the dependent software required by the app, I've rebooted the system but no resolution yet.
Can you please let me know what I'm doing wrong?

Any help is much appreciated!

Best,
PE

@xingdongzhe
Copy link

I will happy to hellpif you can provider mini reproduce of only use gunicorn -c gunicorn.config.py wsgi:app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants