gunicorn daemon (active: failed) / curl(56) Recv Failure: Connection reset by peer
Asked Answered
S

4

5

First thing, I am not sure if this is better here or on ask ubuntu (ubuntu did not have a 'gunicorn' tag so I think i'm in the right place). If it is not appropriate here just drop it in the comments and I'll close it.

I am following a digitalocean tutorial on deployment(https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04).I am up to gunicorn set up. I'm at my wits end trying to get this gunicorn to work, so I have come here. Anything in quotes is the name of the current section in the article. I got up to "Checking for the Gunicorn Socket File" and "check for the existence of the gunicorn.sock file within the /run directory:" before failure. Check for socket file:

  sudo systemctl status gunicorn.socket returns
    Failed to dump process list, ignoring: No such file or directory
    ● gunicorn.socket - gunicorn socket
       Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor pres
       Active: active (listening) since Fri 2020-02-21 21:34:06 UTC; 1min 8s ago
       Listen: /run/gunicorn.sock (Stream)
       CGroup: /system.slice/gunicorn.socket

Check for existence of gunicorn.sock:

file /run/gunicorn.sock

output: /run/gunicorn.sock: socket

Upon "Testing socket activation", it fails:

sudo systemctl status gunicorn

output:

● gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service;
   Active: failed (Result: exit-code) since Fri 2020-02-
 Main PID: 15708 (code=exited, status=217/USER)

Feb 21 21:32:39 ubuntu-s-1vcpu-1gb-nyc3-01 systemd[1]: S
Feb 21 21:32:39 ubuntu-s-1vcpu-1gb-nyc3-01 systemd[15708
Feb 21 21:32:39 ubuntu-s-1vcpu-1gb-nyc3-01 systemd[15708
Feb 21 21:32:39 ubuntu-s-1vcpu-1gb-nyc3-01 systemd[1]: g
Feb 21 21:32:39 ubuntu-s-1vcpu-1gb-nyc3-01 systemd[1]: g
Feb 21 21:32:39 ubuntu-s-1vcpu-1gb-nyc3-01 systemd[1]: g
Feb 21 21:32:39 ubuntu-s-1vcpu-1gb-nyc3-01 systemd[1]: g
Feb 21 21:32:39 ubuntu-s-1vcpu-1gb-nyc3-01 systemd[1]: F
lines 1-13/13 (END)

It says to test socket activation, do the following:

curl --unix-socket /run/gunicorn.sock localhost

output(says I should see HTML):

curl: (56) Recv failure: Connection reset by peer

Not sure if I provided enough info. Below I will include my gunicorn.socket and gunicorn.service files as well as the layout of directories on my server.

gunicorn.socket:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

gunicorn.service:

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

[Service]
User=justin
Group=www-data
WorkingDirectory=/home/justin/project
ExecStart=/home/justin/project/env/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          jobzumo.wsgi:application
[Install]
WantedBy=multi-user.target

Layout of server/project:

home/justin/project/

This project/ folder contains env(env/bin/gunicorn does exist), jobzumo(django project), manage.py and static.

The only thing I am thinking is that I may have created these gunicorn files while using root and now I am trying to modify them using the user justin? Not really sure what is going on here. If I did not provide enough info or if you need me to run any type of debug commands please let me know. Thanks for any help.

Slime answered 22/2, 2020 at 4:4 Comment(0)
T
5

I had the exact same propblem following this tutorial. OP's answer did not help in my case but I found a solution here. Maybe it helps others stubmling over this.

Many thanks to RussellMolimock for the following comment, which I found there!

"Go back into your virtualenv with source [your_project_env]/bin/activate and enter which gunicorn That will return the path to your gunicorn exectuable.

Paste that into the path section of the ‘ExecStart’ value inside the ’/etc/systemd/system/gunicorn.service’ file, and run the ‘sudo systemctl daemon-reload’ and 'sudo systemctl restart gunicorn’ commands to restart your daemon and try curling again with curl –unix-socket /run/gunicorn.sock localhost

I hope this helps!"

Triecious answered 7/7, 2020 at 11:50 Comment(0)
S
1

I had to run the following two commands:

sudo ufw delete allow 8000
sudo ufw allow 'Nginx Full'

and now everything is working. Apparently this opens my firewall up to port 80. Not sure why as I don't specify port 80 there, but it is working.

Slime answered 22/2, 2020 at 4:19 Comment(0)
B
0

I faced this error because Gunicorn was not able to read the environment variables. This helped me in defining the environment variables for Gunicorn.

Bianca answered 13/11, 2021 at 14:0 Comment(0)
S
0

I deleted the whole project folder in Ubuntu (home/user/project) and restarted from the beginning, and it worked. I have tried multiple solutions on the Internet, restarting the daemon and changing the path of gunicorn, all fail.

Stereoscopy answered 21/8, 2022 at 6:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.