user1424311
user1424311

Reputation: 417

gunicorn does not start after boot

I'm running a Debian web server with nginx and gunicorn running a django app. I've got everything up and running just fine but after rebooting the server I get a 502 bad gateway error. I've traced the issue back to gunicorn being inactive after the reboot. If I start the service the problem is fixed until I reboot the server again.

Starting the service:

systemctl start gunicorn.service

After the reboot here is my gunicorn service status:

{username}@instance-3:~$ sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled)
Active: inactive (dead)

Contents of my /etc/systemd/system/gunicorn.service file:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User={username}
Group={username}
WorkingDirectory=/home/{username}/web/{projname}
ExecStart=/usr/local/bin/gunicorn {projname}.wsgi:application
Restart=on-failure

[Install]
WantedBy=multi.user.target

Any ideas to figure out why the gunicorn service isn't starting after reboot?

Edit:

Could the issue be that the gunicorn.conf has a different dir in chdir and the exec than the working directory?

{username}@instance-3:~$ cat /etc/init/gunicorn.conf 
cription "Gunicorn application server handling {projname}"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid {username}
setgid {username}
chdir /home/data-reporting/draco_reporting

exec {projname}/bin/gunicorn --workers 3 --bind unix:/home/{username}/data-reporting/{projname}/{projname}.sock {projname}.wsgi:application

Upvotes: 11

Views: 7340

Answers (2)

Developer Vicky
Developer Vicky

Reputation: 1163

I made old school crontab and the problem was solved.

crontab -e

and then

@reboot sudo systemctl restart nginx && sudo systemctl restart gunicorn.service

enter image description here

and just save crontab.

Upvotes: 0

nik_m
nik_m

Reputation: 12086

You have a small typo in your gunicorn.service file. Change to:

WantedBy=multi-user.target

Also, you may want to change to:

Restart=always

Upvotes: 8

Related Questions