Service gunicorn not starting code=exited, status=203/EXEC

Question:

I am trying to configure a gunicorn service on an Red hat EC2 vm of amazon.

I created the sercvice file, but when I run it and check the status it tells me that it failed:

[Unit]  

Description=Gunicorn instance for a simple hello world app 

After=network.target

[Service] 

User=ec2-user

Group=nginx

WorkingDirectory=/home/ec2-user/webserverflask 

Environment="PATH=/home/ec2-user/webserverflask/venv/bin" 

ExecStart=/home/ec2-user/webserverflask/venv/bin/gunicorn --workers 3
--bind unix:webserverflask.sock -m 007 wsgi 

Restart=always


[Install] 

WantedBy=multi-user.target

The error message:

● webserver.service – Gunicorn instance for a simple hello world app
Loaded: loaded (/etc/systemd/system/webserver.service; enabled; vendor
preset: disabled) Active: failed (Result: exit-code) since Wed
2022-07-06 19:31:08 UTC; 20h ago Main PID: 25957 (code=exited,
status=203/EXEC)

Jul 06 19:31:08 ip-172-31-95-13.ec2.internal systemd[1]:
webserver.service: Main process exited, code=exited, status=203/EXEC
Jul 06 19:31:08 ip-172-31-95-13.ec2.internal systemd[1]:
webserver.service: Failed with result ‘exit-code’. Jul 06 19:31:08
ip-172-31-95-13.ec2.internal systemd[1]: webserver.service: Service
RestartSec=100ms expired, scheduling restart. Jul 06 19:31:08
ip-172-31-95-13.ec2.internal systemd[1]: webserver.service: Scheduled
restart job, restart counter is at 5. Jul 06 19:31:08
ip-172-31-95-13.ec2.internal systemd[1]: Stopped Gunicorn instance for
a simple hello world app. Jul 06 19:31:08 ip-172-31-95-13.ec2.internal
systemd[1]: webserver.service: Start request repeated too quickly. Jul
06 19:31:08 ip-172-31-95-13.ec2.internal systemd[1]:
webserver.service: Failed with result ‘exit-code’. Jul 06 19:31:08
ip-172-31-95-13.ec2.internal systemd[1]: Failed to start Gunicorn
instance for a simple hello world app.

and here is my wsgi:

from app import app as application
if __name__ == "__main__":
    app.run()

and flask app:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == "__main__":
    app.run()
Asked By: Noubir Nacer

||

Answers:

I would start debugging by trying to run the ExecStart command manually, and see if that works (or what error you get):

$ cd /home/ec2-user/webserverflask
$ /home/ec2-user/webserverflask/venv/bin/gunicorn --workers 3 --bind unix:webserverflask.sock -m 007 wsgi 
Answered By: Mark Bailey

I managed to solve the issue.
If anyone had the same issue while trying to deploy a flask gunicorn using the tutorials on internet, here is my answer:

The problem was that the gunicorn file wasn’t accessible, I still don’t know why but I managed to fix the issue by moving gunicorn to /usr/local/bin/gunicorn

So my service file look like this now:

[Unit]
Description=Gunicorn instance for a simple hello world app
After=network.target

[Service]
User=ec2-user
Group=nginx
ExecStart=/usr/local/bin/gunicorn --workers 3 --chdir /home/ec2-user --bind unix                                                                                 :webserverflask.sock -m 007 webserverflask.wsgi


[Install]
WantedBy=multi-user.target
Answered By: Noubir Nacer
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.