Gunicorn sock file is missing?

4,473 views
Skip to first unread message

Kaloian

unread,
Feb 25, 2015, 1:16:36 AM2/25/15
to django...@googlegroups.com

I have an ansible provisioned VM based on this one https://github.com/jcalazan/ansible-django-stack but for some reason trying to start Gunicorn gives the following error:

Can't connect to /path/to/my/gunicorn.sock

and in nginx log file:

connect() to unix:/path/to/my/gunicorn.sock failed (2: No such file or directory) while connecting to upstream

And the socket file is really missing in the specified directory. I have checked the permissions of the directory and they are fine.

Here is my gunicorn_start script:


NAME="{{ application_name }}"
DJANGODIR
={{ application_path }}
SOCKFILE
={{ virtualenv_path }}/run/gunicorn.sock
USER
={{ gunicorn_user }} GROUP={{ gunicorn_group }}
NUM_WORKERS
={{ gunicorn_num_workers }}

# Set this to 0 for unlimited requests. During development, you might want to # set this to 1 to automatically restart the process on each request (i.e. your # code will be reloaded on every request).
MAX_REQUESTS
={{ gunicorn_max_requests }}
echo
"Starting $NAME as `whoami`"
# Activate the virtual environment.
cd $DJANGODIR
. ../../bin/activate
# Set additional environment variables.
. ../../bin/postactivate
# Create the run directory if it doesn't exist.
RUNDIR
=$(dirname $SOCKFILE) test -d $RUNDIR || mkdir -p $RUNDIR
# Programs meant to be run under supervisor should not daemonize themselves # (do not use --daemon).
exec gunicorn \ --name $NAME \
   
--workers $NUM_WORKERS \
   
--max-requests $MAX_REQUESTS \
   
--user $USER --group $GROUP \
   
--log-level debug \
   
--bind unix:$SOCKFILE \
   
{{ application_name }}.wsgi


Can anyone point me to any direction what could be causing the missing gunicorn.sock file ?

Thanks

Erik Cederstrand

unread,
Feb 25, 2015, 4:55:43 AM2/25/15
to Django Users

> Den 25/02/2015 kl. 07.16 skrev Kaloian <kaloian...@gmail.com>:
>
> I have an ansible provisioned VM based on this one https://github.com/jcalazan/ansible-django-stack but for some reason trying to start Gunicorn gives the following error:
>
> Can't connect to /path/to/my/gunicorn.sock
>
> [...]
>
> Can anyone point me to any direction what could be causing the missing gunicorn.sock file ?

Is gunicorn even running? If not, you ned to find out why it failed to start, or why it crashed. As a start, try adding the absolute path to gunicorn in your gunicorn_start script instead of just "exec gunicorn".

Erik

Kaloian

unread,
Feb 26, 2015, 1:56:11 AM2/26/15
to django...@googlegroups.com
Hi Erik,

No it doesn't start at all, running the gunicorn_start script gives:

[ERROR] Retrying in 1 second.
[ERROR] Retrying in 1 second.
[ERROR] Retrying in 1 second.
[ERROR] Retrying in 1 second.
[ERROR] Retrying in 1 second.
[ERROR] Can't connect to /path/to/my/gunicorn.sock

This is why I thought that the missing sock file is failing it to start. Do you think it could be something else?
I have already tried to add the absolute path in gunicorn_start but nothing changed.

Thanks,
Kaloian

Erik Cederstrand

unread,
Feb 26, 2015, 3:47:41 AM2/26/15
to Django Users

> Den 26/02/2015 kl. 07.56 skrev Kaloian <kaloian...@gmail.com>:
>
> Hi Erik,
>
> No it doesn't start at all, running the gunicorn_start script gives:
>
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Can't connect to /path/to/my/gunicorn.sock
>
> This is why I thought that the missing sock file is failing it to start. Do you think it could be something else?
> I have already tried to add the absolute path in gunicorn_start but nothing changed.

A UNIX socket is like a TCP connection, except it's represented as a file. gunicorn is supposed to create it on startup and destroy it on shutdown, and it shouldn't be present when gunicorn is not running.

Maybe you tried to create /path/to/my/gunicorn.sock yourself, and the file is now garbage? Try deleting it. Otherwise, another instance of gunicorn may be running already. Try "ps aux | grep gunicorn" or "lsof -U | grep gunicorn" if you're on Linux. Also, the user running gunicorn_start must have access to create files in /path/to/my/

Erik

Kaloian

unread,
Mar 6, 2015, 7:30:53 AM3/6/15
to django...@googlegroups.com
Hi Erik, and thanks for the help.

Well it appears to be a permission issue after all, but I really cannot understand why. I tried to change the directory for the sock file from /webapps/my-app/run/gunicorn.sock to /sockets/gunicorn.sock and gunicorn started normally. I tried to give full permissions to /webapps/my-app/run/ but still no success. I never tried to create the sock file myself and the /webapps/my-app/run/ dir is empty all the time. I cannot understand what is stopping gunicorn from creating the sock file in this directory.

Regards,
Kaloian

aRkadeFR

unread,
Mar 6, 2015, 10:01:55 AM3/6/15
to django...@googlegroups.com

On 03/06/2015 01:30 PM, Kaloian wrote:
Hi Erik, and thanks for the help.

Well it appears to be a permission issue after all, but I really cannot understand why. I tried to change the directory for the sock file from /webapps/my-app/run/gunicorn.sock to /sockets/gunicorn.sock and gunicorn started normally. I tried to give full permissions to /webapps/my-app/run/ but still no success. I never tried to create the sock file myself and the /webapps/my-app/run/ dir is empty all the time. I cannot understand what is stopping gunicorn from creating the sock file in this directory.

Did you try to sudo to the user running gunicorn and creating the socket?
Some hints:
- The user can't access the directory cause he is not allowed to index one of his parent
- The user isn't in one of the new group cause he is logged in
- ... ?

Most of the time sudo to the user is useful for me


Regards,
Kaloian

On Thursday, February 26, 2015 at 10:47:41 AM UTC+2, Erik Cederstrand wrote:

> Den 26/02/2015 kl. 07.56 skrev Kaloian <kaloian...@gmail.com>:
>
> Hi Erik,
>
> No it doesn't start at all, running the gunicorn_start script gives:
>
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Retrying in 1 second.
> [ERROR] Can't connect to /path/to/my/gunicorn.sock
>
> This is why I thought that the missing sock file is failing it to start. Do you think it could be something else?
> I have already tried to add the absolute path in gunicorn_start but nothing changed.

A UNIX socket is like a TCP connection, except it's represented as a file. gunicorn is supposed to create it on startup and destroy it on shutdown, and it shouldn't be present when gunicorn is not running.

Maybe you tried to create /path/to/my/gunicorn.sock yourself, and the file is now garbage? Try deleting it. Otherwise, another instance of gunicorn may be running already. Try "ps aux | grep gunicorn" or "lsof -U | grep gunicorn" if you're on Linux. Also, the user running gunicorn_start must have access to create files in /path/to/my/

Erik
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/59fe3b92-d9d7-4e03-b8f3-b0be1c355d78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kaloian

unread,
Mar 7, 2015, 7:57:01 AM3/7/15
to django...@googlegroups.com, con...@arkade.info
Did you try to sudo to the user running gunicorn and creating the socket?
Do you mean to create the socket manually? Haven't tried that. 

The directory and all its parents are owned by the user running gunicorn and also have 777 permissions. I am no sure I understand what you mean by - "The user isn't in one of the new group cause he is logged in" . 
Is it possible the reason to be something from the virtual env since the directory  /webapps/my-app/run/ is inside virtual env path. 

Thanks,
Kaloian
Reply all
Reply to author
Forward
0 new messages