与主管开始枪炮的麻烦

时间:2014-02-21 23:08:19

标签: python django virtualenv gunicorn supervisord

我是django的新手并熟悉它。

我正在使用主管和枪手。我正在读这本书“实用的django项目”。 django,主管等所有东西都在virtualenv中运行。

我正在尝试创建一个django的独立应用程序。我创建了一个名为blog的文件夹,并将其放在主目录下。然后我添加了PYTHONPATH的路径。我可以清楚地看到从ipython成功添加的python路径。但是当我将这个博客添加到我的django项目的已安装应用程序设置时,主管开始给出麻烦。

我已经看到了日志文件及其No module named blog

我的主管conf文件是这个

[program:gunicorn]
command = ./manage.py run_gunicorn -w 4 -k gevent
directory = /home/krishna/workspace/django/learn/
user = krishna
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/gunicorn.log
stderr_logfile = /var/log/supervisor/gunicorn_err.log

但更让我失望的是,当我使用终端中supervisor conf文件中的命令时,gunicorn开始和平。

其他信息:

sys.path的输出

/home/krishna/.virtualenvs/py1/bin
/home/krishna/workspace/django/apps
/home/krishna/workspace/django
/home/krishna/workspace
/home/krishna/workspace/django/learn
/home/krishna/.virtualenvs/py1/lib/python2.7
/home/krishna/.virtualenvs/py1/lib/python2.7/plat-x86_64-linux-gnu
/home/krishna/.virtualenvs/py1/lib/python2.7/lib-tk
/home/krishna/.virtualenvs/py1/lib/python2.7/lib-old
/home/krishna/.virtualenvs/py1/lib/python2.7/lib-dynload
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/home/krishna/.virtualenvs/py1/local/lib/python2.7/site-packages
/home/krishna/.virtualenvs/py1/local/lib/python2.7/site-packages/IPython/extensions

我的博客文件夹位于/home/krishna/workspace/django/apps

编辑:我包含了我的博客文件夹的文件结构

drwxr-xr-x 2 krishna krishna  4096 Feb 22 01:12 .
drwxr-xr-x 3 krishna krishna  4096 Feb 22 00:17 ..
-rw-r--r-- 1 krishna krishna     0 Feb 22 00:18 admin.py
-rw-r--r-- 1 krishna krishna   136 Feb 22 01:09 admin.pyc
-rw-r--r-- 1 krishna krishna 12288 Feb 22 00:27 .admin.py.swp
-rw-r--r-- 1 krishna krishna     0 Feb 22 00:17 __init__.py
-rw-r--r-- 1 krishna krishna   139 Feb 22 00:33 __init__.pyc
-rw-r--r-- 1 krishna krishna   222 Feb 22 00:23 models.py
-rw-r--r-- 1 krishna krishna   743 Feb 22 00:33 models.pyc
-rw-r--r-- 1 krishna krishna     0 Feb 22 00:18 views.py

2 个答案:

答案 0 :(得分:1)

您需要将PYTHONPATH放入环境supervisord created以运行./manage.py,supervisord不会从您设置PYTHONPATH的任何地方继承环境变量。

[program:gunicorn]
command = ./manage.py run_gunicorn -w 4 -k gevent
directory = /home/krishna/workspace/django/learn/
user = krishna
autostart = true
autorestart = true
environment=PYTHONPATH="[Your PYTHONPATH goes here]"
stdout_logfile = /var/log/supervisor/gunicorn.log
stderr_logfile = /var/log/supervisor/gunicorn_err.log

有关详细信息,请查看the docs中的environment

答案 1 :(得分:0)

我配置了一个具有类似设置的系统。我使用安装在virtualenv主目录的gunicorn_django目录中的bin包装器来启动django项目。包装纸由gunicorn提供。

我认为这对您有用(只需记住调整virtalenv目录的路径):

[program:gunicorn]
command=/path/to/virtualenv_dir/bin/gunicorn_django -w 4 -k gevent
directory=/home/krishna/workspace/django/learn/
user=krishna
autostart=true
autorestart=true
stdout_logfile = /var/log/supervisor/gunicorn.log
stderr_logfile = /var/log/supervisor/gunicorn_err.log