gunicorn: Can't connect to gunicorn.sock
Asked Answered
D

3

14

I am using Django 1.8 and I want to run my application with gunicorn.

I can run it OK from the command line binding to my IP:

gunicorn myapp.wsgi:application --bind xx.xx.xx.xx:8001

But now I want to run it via a Unix socket:

gunicorn myapp.wsgi:application --bind=unix$/webapps/myapp/run/gunicorn.sock

I get this error:

[2015-08-23 07:38:04 +0000] [18598] [INFO] Starting gunicorn 19.3.0
[2015-08-23 07:38:04 +0000] [18598] [ERROR] Retrying in 1 second.
[2015-08-23 07:38:05 +0000] [18598] [ERROR] Retrying in 1 second.
[2015-08-23 07:38:06 +0000] [18598] [ERROR] Retrying in 1 second.
[2015-08-23 07:38:07 +0000] [18598] [ERROR] Retrying in 1 second.
[2015-08-23 07:38:08 +0000] [18598] [ERROR] Retrying in 1 second.
[2015-08-23 07:38:09 +0000] [18598] [ERROR] Can't connect to $/webapps/myapp/run/gunicorn.sock

If I do ls -al /webapps/myapp/run I see that the socket file does exist, though it is empty:

srwxrwxrwx 1 opuser webapps 0 Aug 23 07:22 /webapps/myapp/run/gunicorn.sock

How can I fix this?

I eventually want to run gunicorn as the user opuser, I've tried appending --user opuser --group webapps to the gunicorn command, but still get the same error.

Dank answered 23/8, 2015 at 11:42 Comment(2)
Are you sure the syntax is unix$PATH, not unix:PATH? The docs seem to suggest the latter.Feeder
I was getting the same message when my user had no permissions to listen the specified port (80 in my case). If this is the case and you want to run the web server under a normal user (not root), run on another port (above 1024) and redirect port 80 to this port using iptables.Accumulator
R
11

According to the documentation (http://gunicorn-docs.readthedocs.org/en/latest/run.html), you should use: unix:$(PATH), meaning your command should read:

gunicorn myapp.wsgi:application --bind=unix:/webapps/myapp/run/gunicorn.sock
Ruhr answered 23/8, 2015 at 13:16 Comment(5)
Changed it - now I get the error OSError: [Errno 13] Permission denied: '/webapps/openprescribing/run/gunicorn.sock which I guess is progress! Any idea how I can fix that? It seems odd since opuser is the owner of the gunicorn.sock file.Dank
I guess I am not running the gunicorn command as opuser, though...? Do I need to give the current user permission to connect to gunicorn.sock as well?Dank
Just for troubleshooting you can grant 777 rights to the socket and see what happens.Ruhr
still the same error. I did sudo chmod 777 /webapps/myapp/run/gunicorn.sock, and ls -lash/webapps/myapp/run/gunicorn.sock now shows 0 srwxrwxrwx 1 opuser webapps 0 Aug 23 07:22 gunicorn.sock. But still the same Permission denied error.Dank
Is there any log details other than that? Other relevant config?Ruhr
D
3

remove venv/run folder and then mkdir run without using sudo

Distribute answered 10/1, 2019 at 12:11 Comment(0)
P
0

In my case the issue was in permissions of the sock file. I created new sock file in home directory of non-sudo user in non-sudo mode and reconfigured and it worked.

Papal answered 19/2, 2023 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.