Report this

What is the reason for this report?

Gunicorn fails to start - 'Job for gunicorn.socket failed'

Posted on May 10, 2019

I’m on Ubuntu 19.04 - is this the problem?

I’ve followed this tutorial:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04

And once I get to the part about starting Gunicorn, I’ve added the commands to gunicorn.socket and gunicorn.service, but following the ‘sudo systemctl start gunicorn.socket’ command, I get an error - 'Job for gunicorn.socket failed.

It asks me to check the status of the socket for details:

 gunicorn.socket - gunicorn socket
   Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
   Active: inactive (dead)
   Listen: /run/gunicorn.sock (Stream)

gunicorn.service

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

[Service]
User=phillyharper
Group=www-data
WorkingDirectory=/home/phillyharper/versal
ExecStart=/home/phillyharper/versal/versalenv/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          versal.wsgi:application

[Install]
WantedBy=multi-user.target

gunicorn.socket

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target



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.

Hey I think I have fixed this.

So the problem was path related. I added one additional folder to working directory of gunicorn.service so it could find my module wsgi.

WorkingDirectory=/home/phillyharper/versal/versal

I had the same issue with the 18.04 instructions. Try using the Systemd instructions on this page instead: https://docs.gunicorn.org/en/20.0.4/deploy.html

description “Gunicorn application server handling myproject”

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

respawn setuid user setgid www-data chdir /home/parallels/books/mysite

exec myprojectenv/bin/gunicorn --workers 3 --bind unix:/home/parallels/books/mysite/mysite.sock mysite.wsgi:application

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.