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
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
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.
Did you try to sudo to the user running gunicorn and creating the socket?