Reputation: 380
So I am trying to run a gunicorn script, following a tutorial I found in the Internet.
Here is my folder structure:
(today_project)[littlem@server1 today_project]$ tree . -L 2
.
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── activate_this.py
│ ├── django-admin.py
│ ├── django-admin.pyc
│ ├── easy_install
│ ├── easy_install-2.7
│ ├── gunicorn
│ ├── gunicorn_django
│ ├── gunicorn_paster
│ ├── gunicorn_start
│ ├── pip
│ ├── pip2
│ ├── pip2.7
│ ├── python -> python2.7
│ ├── python2 -> python2.7
│ └── python2.7
├── include
│ ├── python2.6 -> /usr/include/python2.6
│ └── python2.7 -> /usr/local/include/python2.7
├── lib
│ ├── python2.6
│ └── python2.7
├── manage.py
├── run
│ └── gunicorn.sock
├── today
│ ├── #app files
├── today_project
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── __pycache__
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
└── TODO.md
When I run
gunicorn today_project.wsgi:application
from my virtualenv, it works fine. But when I run this script (I pretty much copied it from somewhere):
#!/bin/bash
NAME="today" # Name of the application
DJANGODIR=~/today_project/today_project # Django project directory
SOCKFILE=~/today_project/run/gunicorn.sock # we will communicte using this unix socket
USER=ferski # the user to run as
GROUP=ferski # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=today.settings # which settings file should Django use
DJANGO_WSGI_MODULE=today.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source ../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 ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--log-level=debug \
--bind=unix:$SOCKFILE
I have the following error
Traceback (most recent call last):
File "/home/ferski/today_project/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
worker.init_process()
File "/home/ferski/today_project/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
self.wsgi = self.app.wsgi()
File "/home/ferski/today_project/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/home/ferski/today_project/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/home/ferski/today_project/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/ferski/today_project/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
__import__(module)
ImportError: No module named today_project.wsgi
2014-04-06 16:09:28 [19420] [INFO] Worker exiting (pid: 19420)
2014-04-06 16:09:28 [19407] [INFO] Shutting down: Master
2014-04-06 16:09:28 [19407] [INFO] Reason: Worker failed to boot.
So I guess its the problem with python version?
I dont know what I am doing to be honest when I do export PYTHONPATH=$DJANGODIR:$PYTHONPATH
but I guess this is where the problem lies
Upvotes: 0
Views: 1037
Reputation: 599450
I think your DJANGODIR should just be ~/today_project/
. It's the root of the tree, not the inner directory.
There are a few other things wrong, too: in particular, since you're running in a virtualenv, you shouldn't need to change the PYTHONPATH at all.
Upvotes: 1