gunicorn does not start after boot
Asked Answered
A

2

11

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
Aram answered 8/5, 2017 at 21:27 Comment(0)
E
8

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
Enchanter answered 9/5, 2017 at 5:47 Comment(3)
Edit: I re-ran systemctl enable gunicorn.service after fixing the typo and now it works as it should. Thanks!Aram
not working, I already have my file in this wayViccora
Also make sure to enable it after modifying. "sudo systemctl enable gunicorn" Unless it won't auto start. You can check the status using "systemctl status gunicorn"Eroticism
C
0

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.

Catenane answered 28/8, 2022 at 7:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.