2013-10-20 57 views
3

我在debian服務器上設置了一個django項目,並在其他東西中安裝了virtualenvwrapper。它從命令行工作正常,但現在我想從腳本激活它。腳本中的其他一切正常,但是我在virtualenvwrapper中遇到錯誤。Virtualenv存在,但不能從bash腳本訪問它

這裏是我的腳本:

#!/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 

和我的日誌:

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 

任何幫助將非常感激!我期望使用我的root用戶是不好的,但這是我第一次。

+0

你用什麼用戶運行腳本爲 – Mark

+0

感謝您的回覆!那麼在腳本中,我說USER = root,所以我希望root用戶,因爲這也是我在終端中運行標記時登錄的內容。 – user1034211

+0

好吧,我試圖測試這一點,我認爲那裏有一個提示。當我去的時候:echo「$ USERNAME」我什麼都沒收,空白的一行。當我把它放在我的腳本中時:root。我搞亂了我的用戶不是我... – user1034211

回答

1

我激活它不使用workon命令和工作:

source <path to your env> 

如果需要的路徑,你的ENV你可以這樣做:

workon <your env name> 
cdvirtualenv 
pwd 

還有你的路徑。

1

試試這個執行你的bash腳本:. ./script.sh