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()
2
Answers
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:
I would start debugging by trying to run the ExecStart command manually, and see if that works (or what error you get):