Hello, I have updated my old Ubuntu server from version 14 to 16. This also included a Django and Python update. After restarting the server, I got a 502 error from Nginx, which I have discovered is being caused by Gunicorn not being able to start. I am able to start gunicorn manually, and the site works perfectly, by doing:
root@server:/home/django/django_project/django_project# gunicorn -b 127.0.0.1:9000 wsgi
wsgi.py is located at /home/django/django_project/django_project
The problem I am having is that the gunicorn service is not able to start automatically, even if the config (/etc/init/gunicorn.conf) looks correct:
[...]
chdir /home/django
exec gunicorn \
--name=django_project \
--pythonpath=django_project \
--bind=127.0.0.1:9000 \
--config /etc/gunicorn.d/gunicorn.py \
django_project.wsgi:application
Any ideas of why the service is not starting by itself anymore?
service gunicorn restart
does not work either.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
So, just for everyone to know, I finally solved this by editing /etc/init/gunicorn.conf
The file was assuming gunicorn was in my django folder, but in reality it is located at /usr/bin
So, the old file was:
The new file is now:
So I made it execute gunicorn from its real location ( it was not there before the update ) and I also cleaned up the command by removing name and pythonpath.
Hi @baroale,
Can you show us the error you are experiencing when you try to perform
If it doesn’t start, it should at least have an error being logged somewhere, perhaps
Regards, KDSys
Hello, first of all, the gunicorn log file is not getting written anymore:
Regarding the log files you mentioned ( journalctl -xe ), what I am getting is:
I also had another idea: Maybe the django user had no permission to run gunicorn ( because I am manually running it as root ), but when I do su django and run the manual gunicorn command, it still runs OK.