Reputation: 4960
I have the following systemd
file at /etc/systemd/system/gunicorn.service
[Unit]
Description=Gunicorn daemon for Django Project
Before=nginx.service
After=network.target
[Service]
WorkingDirectory=/home/serverapp
ExecStart=gunicorn --name=avesoft --bind unix:/home/serverapp/gunicorn.socket --config /etc/gunicorn.d/gunicorn.py WebApp.wsgi:application
Restart=always
SyslogIdentifier=gunicorn
User=root
Group=www-data
[Install]
WantedBy=multi-user.target
When I manually change the directory to /home/serverapp
and run gunicorn --name=avesoft --bind unix:/home/serverapp/gunicorn.socket --config /etc/gunicorn.d/gunicorn.py WebApp.wsgi:application
everything works fine and Nginx connects to my Django app through Gunicorn.
But by rebooting the server, I get Bad Gateway error that seems Gunicorn has not started working. I don't get what is the reason behind my service file not working.
Upvotes: 0
Views: 1204
Reputation: 4960
So I fixed that problem by providing the path for gunicorn
:
[Unit]
Description=Gunicorn daemon for Django Project
Before=nginx.service
After=network.target
[Service]
WorkingDirectory=/home/serverapp
ExecStart=/usr/bin/gunicorn --name=avesoft --bind unix:/home/serverapp/gunicorn.socket --config /etc/gunicorn.d/gunicorn.py WebApp.wsgi:application
Restart=always
SyslogIdentifier=gunicorn
User=root
Group=www-data
[Install]
WantedBy=multi-user.target
Upvotes: 1