Hi everyone,
I’m trying to follow this tutorial on hosting my django app: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04#prerequisites-and-goals
I’m on the step “Check for the Gunicorn Socket File” - everything before that has been very successful. However, when I try this step, I just get an unhelpful error message.
Here is my /etc/systemd/system/gunicorn.service file:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=arya
Group=www-data
WorkingDirectory=/home/arya/measuring_polyphony_django
ExecStart=/home/arya/envs/polyphonynev/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/arya/measuring_polyphony_django/measuring_polyphony.sock measuring_polyphony.wsgi:application
[Install]
WantedBy=multi-user.target
Here’s the message I get when I run sudo systemctl status gunicorn
arya@polyphony:~$ sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2017-05-27 16:04:09 UTC; 13min ago
Main PID: 9039 (code=exited, status=203/EXEC)
May 27 16:04:09 polyphony systemd[1]: Started gunicorn daemon.
May 27 16:04:09 polyphony systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
May 27 16:04:09 polyphony systemd[1]: gunicorn.service: Unit entered failed state.
May 27 16:04:09 polyphony systemd[1]: gunicorn.service: Failed with result 'exit-code'.
There is no measuring_polyphony.sock file either.
Here’s what sudo journalctl -u gunicorn says:
May 27 16:04:09 polyphony systemd[1]: Started gunicorn daemon.
May 27 16:04:09 polyphony systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
May 27 16:04:09 polyphony systemd[1]: gunicorn.service: Unit entered failed state.
May 27 16:04:09 polyphony systemd[1]: gunicorn.service: Failed with result 'exit-code'.
So not much more helpful than the previous command. To go through all the things that were listed as could go wrong in the guide:
arya@polyphony:~$ ls /home/arya/measuring_polyphony_django
importer.py measuring.csv media my_project_visualized.png schema.png static viewer
manage.py measuring_polyphony mei_files __pycache__ secrets.py templates
3a. The path to Gunicorn is the correct one for my virtualenv (and the one I used to test gunicorn earlier in the tutorial)
arya@polyphony:~$ source ~/envs/polyphonynev/bin/activate
(polyphonynev) arya@polyphony:~$ which gunicorn
/home/arya/envs/polyphonynev/bin/gunicorn
3b. The directory in the --bind option is definitely able to be created (I tested by running nano and saving a random file to the directory)
3c. The “measuring_polyphony.wsgi” setting definitely translates to this folder in the WORKING_DIRECTORY
(polyphonynev) arya@polyphony:~/measuring_polyphony_django$ ls measuring_polyphony/wsgi.py
measuring_polyphony/wsgi.py
Does anyone else see what could be wrong with this? Thank you!
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.
I was also experiencing the same issue. I changed the code User=arya
to User=root
I think the project files are owned by the root user instead of a sudo user So try changing your service file to something like this:
[Service]
User=root
Group=www-data
WorkingDirectory=/root/measuring_polyphony_django
ExecStart=/root/envs/polyphonynev/bin/gunicorn --access-logfile - --workers 3 --bind unix:/root/measuring_polyphony_django/measuring_polyphony.sock measuring_polyphony.wsgi:application
I was also experiencing the same issue; added --log-level debug
to ExecStart
and was able to find that the environment variables weren’t being loaded, added EnvironmentFile=path\to\.env
to the [Service]
section and was able to fix the problem.
THANK YOU SOO MUCH I FOLLOW THE GUIDE AS YOU SAID.!!!
hey, i do this all but i can’t get result exit-code, it show “active:failed”, what I do
it solved with change owner user to root in /systemd/gunicorn/
If you’re getting status=203/EXEC
chances are you haven’t ran pip install gunicorn
in your virtualenv yet. You can check by seeing if yourvenv/bin/gunicorn
exists or my running pip show gunicorn
in your virtual environment.
Thank you so much for the guide,it has really helped me
I Encountered same problem that consumed around 2hr to resolve
Here are a few things I noted with gunicorn and virtual environments
gunicorn --bind 0.0.0.0:8000 myproject.wsgi
will run despite gunicorn installation descripacies
Gurnicon service can and will only run from a virtual environment
Avoid using python -m venv myproject
and adopt python virtualenv -p python3 myproject`` if running python-3.x or
python virtualenv myproject``` if running python-2.x
Once you have created and activated myproject
virtual wrapper run pip install django gunicorn psycopg2
as is. Incase of dependancy errors, try other fixes than breaking the line of code.
Countercheck gunicorn
file is created under /path/to/myproject_virtualwrapper/bin/*
. If this file is not created here Gurnicorn was installed elsewhere implying service run error.
If confirmed gurnicorn exists at /path/to/myproject_virtualwrapper/bin/*
, proceed with other configurations as outlined here
try let your gunicorn user and group own the usr folder…
This comment has been deleted
This isn’t a formal solution but my problem came from not having all of the requisite packages installed in my virtualenv
I have this same issue!