Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 339
user1424311 Avatar asked May 08 '17 21:05

user1424311


Video Answer


1 Answers

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
like image 66
nik_m Avatar answered Sep 23 '22 12:09

nik_m