I am running a Django project and I want Gunicorn and Nginx to serve this project. I am using Gunicorn 19.5.
The problem is basically that my socket file doesn't get created and I tried everything (chmod 777, chown, ...) and nothing is working.
Here is my bash script to start gunicorn:
#!/bin/bash
NAME="hello_project" # Name of the application
DJANGODIR=/home/ubuntu/git/hello_project # Django project directory
SOCKFILE=/home/ubuntu/git/hello_project/run/gunicorn.sock # we will communicte using this unix socket
LOG_FILE=/home/ubuntu/git/hello_project/logs/gunicorn.log
USER=ubuntu # the user to run as
GROUP=ubuntu # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
MAX_REQUESTS=1 # reload the application server for each request
DJANGO_SETTINGS_MODULE=hello_project.settings # which settings file should Django use
DJANGO_WSGI_MODULE=hello_project.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source ~/.virtualenvs/hello_project/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn’t exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use –daemon)
exec ~/.virtualenvs/hello_project/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
–name $NAME \
–workers $NUM_WORKERS \
–max-requests $MAX_REQUESTS \
–user=$USER –group=$GROUP \
–bind=unix:$SOCKFILE \
–log-level=debug \
–log-file=$LOG_FILE
I am getting crazy here, there is no log file where I can look at, I even tried to create the socket file myself with no success. I suspect it's a permission problem but even when I run the script with sudo, it doesn't work. My directory "run" gets created though.
Here is the nginx error from the error.log file:
2016/05/19 16:56:32 [crit] 11053#0: *28 connect() to unix:/home/ubuntu/git/hello_project/run/gunicorn.sock failed (2: No such file or directory) while connecting to upstream...
Any clue ?
Thanks a lot,
Try running the script without doing exec ~/.virtualenvs/hello_project/bin/gunicorn
.
Instead try running it with gunicorn
then the args.
This is assuming you have permission to install gunicorn on the system without a virtualenv.
I have a gist that starts the same process you're trying to run. (Django, Nginx, Gunicorn) https://gist.github.com/marcusshepp/129c822e2065e20122d8
I see you're using supervisor
so you're going to not want to use the --deamon
option that I use in my script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With