ImportError: Shell script to start Gunicorn fails to find module
ImportError: Shell script to start Gunicorn fails to find module
给定以下基于 Django REST framework and virtualenv 的 "productsapi" 应用程序的文件夹结构。
/webapps/
└── projects
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── activate_this.py
│ ├── django-admin
│ ├── django-admin.py
│ ├── easy_install
│ ├── easy_install-2.7
│ ├── gunicorn
│ ├── gunicorn_django
│ ├── gunicorn_paster
│ ├── gunicorn_start.sh
│ ├── pip
│ ├── pip2
│ ├── pip2.7
│ ├── python
├── include
├── lib
├── local
├── logs
├── run
├── static
└── productsapi
├── products
├── manage.py
├── requirements.txt
└── productsapi
为此我想准备一份start script for gunicorn as described an article from 2013。我想出了以下内容:
#!/bin/bash
NAME="productsapi" # Name of the application
DJANGODIR=/webapps/projects/ # Django project directory
USER=exampleuser # User to run as
GROUP=examplegroup # Group to run as
NUM_WORKERS=3 # Worker processes to spawn
DJANGO_SETTINGS_MODULE=productsapi.settings # Settings file should Django use
DJANGO_WSGI_MODULE=productsapi.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
# 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 \
--bind=127.0.0.0:8080 \
--log-level=DEBUG \
--log-file=-
我启动脚本如下:
$ /webapps/projects/bin/gunicorn_start.sh
失败并显示以下错误消息:
ImportError: No module named productsapi.wsgi
我好像有些路径设置不正确。
我可以在执行以下操作时启动应用程序服务器(注意不同的路径):
$ cd /webapps/projects/productsapi
$ gunicorn productsapi.wsgi:application --user=exampleuser \
--groups=exampleuser --bind 127.0.0.1:8080 --log-file=- --log-level DEBUG
如您所见,您的 DJANGODIR 应该是 /webapps/projects/productsapi
。
基本上应该是有manage.py
.
的目录
您需要在 exec 行中将 ./bin/
更改为 ../bin
。
给定以下基于 Django REST framework and virtualenv 的 "productsapi" 应用程序的文件夹结构。
/webapps/
└── projects
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── activate_this.py
│ ├── django-admin
│ ├── django-admin.py
│ ├── easy_install
│ ├── easy_install-2.7
│ ├── gunicorn
│ ├── gunicorn_django
│ ├── gunicorn_paster
│ ├── gunicorn_start.sh
│ ├── pip
│ ├── pip2
│ ├── pip2.7
│ ├── python
├── include
├── lib
├── local
├── logs
├── run
├── static
└── productsapi
├── products
├── manage.py
├── requirements.txt
└── productsapi
为此我想准备一份start script for gunicorn as described an article from 2013。我想出了以下内容:
#!/bin/bash
NAME="productsapi" # Name of the application
DJANGODIR=/webapps/projects/ # Django project directory
USER=exampleuser # User to run as
GROUP=examplegroup # Group to run as
NUM_WORKERS=3 # Worker processes to spawn
DJANGO_SETTINGS_MODULE=productsapi.settings # Settings file should Django use
DJANGO_WSGI_MODULE=productsapi.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
# 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 \
--bind=127.0.0.0:8080 \
--log-level=DEBUG \
--log-file=-
我启动脚本如下:
$ /webapps/projects/bin/gunicorn_start.sh
失败并显示以下错误消息:
ImportError: No module named productsapi.wsgi
我好像有些路径设置不正确。
我可以在执行以下操作时启动应用程序服务器(注意不同的路径):
$ cd /webapps/projects/productsapi
$ gunicorn productsapi.wsgi:application --user=exampleuser \
--groups=exampleuser --bind 127.0.0.1:8080 --log-file=- --log-level DEBUG
如您所见,您的 DJANGODIR 应该是 /webapps/projects/productsapi
。
基本上应该是有manage.py
.
您需要在 exec 行中将 ./bin/
更改为 ../bin
。