Flo*_*off 7 python django virtualenv supervisord gunicorn
我的 virtualenv + gunicorn 设置有一个奇怪的问题,只有当 gunicorn 通过 supervisord 启动时。我确实意识到这很可能是我的主管的问题,我将不胜感激任何有关寻求帮助的更好地方的反馈...
简而言之:当我从我的用户 shell 运行 gunicorn 时,在我的 virtualenv 中,一切都完美无缺。我能够访问我的 Django 项目的所有视图。
当系统启动时supervisord启动gunicorn时,一切正常。
但是,如果我必须终止 gunicorn_django 进程,或者如果我执行 supervisord 重新启动,一旦 gunicorn_django 重新启动,每个请求都会用奇怪的 Traceback 回答:
(...)
File "/home/hc/prod/venv/lib/python2.6/site-packages/Django-1.2.5-py2.6.egg/django/db/__init__.py", line 77, in
connection = connections[DEFAULT_DB_ALIAS]
File "/home/hc/prod/venv/lib/python2.6/site-packages/Django-1.2.5-py2.6.egg/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/hc/prod/venv/lib/python2.6/site-packages/Django-1.2.5-py2.6.egg/django/db/utils.py", line 50, in load_backend
raise ImproperlyConfigured(error_msg)
TemplateSyntaxError: Caught ImproperlyConfigured while rendering: 'django.db.backends.postgresql_psycopg2' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name utils
Run Code Online (Sandbox Code Playgroud)
完整堆栈可在此处获得:http : //pastebin.com/BJ5tNQ2N
我在跑...
枪炮配置:
backlog = 2048
bind = "127.0.0.1:8000"
pidfile = "/tmp/gunicorn-hc.pid"
daemon = True
debug = True
workers = 3
logfile = "/home/hc/prod/log/gunicorn.log"
loglevel = "info"
Run Code Online (Sandbox Code Playgroud)
监督配置:
[program:gunicorn]
directory=/home/hc/prod/hc
command=/home/hc/prod/venv/bin/gunicorn_django -c /home/hc/prod/hc/gunicorn.conf.py
user=hc
umask=022
autostart=True
autorestart=True
redirect_stderr=True
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?我已经被这个问题困住了很长一段时间。
这似乎是一些奇怪的内存限制,因为我没有强制执行任何特殊的操作:
$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 20
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Run Code Online (Sandbox Code Playgroud)
我在 gunicorn 开发人员 davisp 的帮助下找到了这个。谢谢 !
这是一个环境问题,由主管 gunicorn 子进程的环境中的无效 HOME 设置引起。
直到我在我的 settings.py 文件中放置了一个“import psycopg2”之后,我才在 stderr 上得到任何信息,这在主管的 gunicorn 的 stderr 文件中产生了以下消息。
Error: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg cache:
[Errno 13] Permission denied: '/root/.python-eggs'"
Run Code Online (Sandbox Code Playgroud)
我在我的 gunicorn 主管配置文件中添加了以下行,现在 Python 找到了通往 u+writable egg 缓存的方法。一切都好。
environment=HOME='/home/hc'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5471 次 |
| 最近记录: |