gunicorn icon indicating copy to clipboard operation
gunicorn copied to clipboard

Gunicorn systemd service unable to start Python Flask WSGI app

Open potequity opened this issue 1 year ago • 1 comments

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

potequity avatar Jan 13 '24 00:01 potequity

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

xingdongzhe avatar Feb 06 '24 07:02 xingdongzhe

no activity since awhile. closing feel free to create a new ticket if needed.

benoitc avatar Aug 06 '24 17:08 benoitc