Question

I am setting up a django project on a debian server and installed virtualenvwrapper among other stuff. It works fine from the command line but now I want to activate it from a script. Everything else in the script works fine but I get an error with the virtualenvwrapper.

Here is my script:

#!/bin/bash

source /usr/local/bin/virtualenvwrapper.sh

NAME="mark"                                      # Name of the application
DJANGODIR=~/webapps                      # Django project directory
SOCKFILE=~/webapps/mark/run/gunicorn.sock        # we will communicte using this unix socket
USER=root                                            # the user to run as
GROUP=root                                                   # the group to run as
NUM_WORKERS=3                                                # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=mark.settings             # which settings file should Django use
DJANGO_WSGI_MODULE=mark.wsgi                     # WSGI module name

echo "Starting $NAME"

# Activate the virtual environment
cd $DJANGODIR
workon mark
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 ~/Envs/mark/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --log-level=debug \
  --bind=unix:$SOCKFILE

and my log:

Starting mark
ERROR: Environment 'mark' does not exist. Create it with 'mkvirtualenv mark'.
2013-10-20 13:54:28 [31640] [INFO] Starting gunicorn 18.0
2013-10-20 13:54:28 [31640] [DEBUG] Arbiter booted
2013-10-20 13:54:28 [31640] [INFO] Listening at: unix:/root/webapps/mark/run/gunicorn.sock (31640)
2013-10-20 13:54:28 [31640] [INFO] Using worker: sync
2013-10-20 13:54:28 [31661] [INFO] Booting worker with pid: 31661
2013-10-20 13:54:28 [31662] [INFO] Booting worker with pid: 31662
2013-10-20 13:54:28 [31663] [INFO] Booting worker with pid: 31663

Any help will be much appreciated! And I expect that it is bad to use my root user but this is my first time.

Était-ce utile?

La solution 2

I activated it without using the workon command and that worked:

source <path to your env>

If you need the path to your env you can do:

workon <your env name>
cdvirtualenv
pwd

And there is your path.

Autres conseils

Try this to execute your bash script: . ./script.sh

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top