Django + gunicorn + virtualenv + Supervisord的问题

只有当gunicorn通过supervisord启动时,我的virtualenv + 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 

全栈可在这里: http : //pastebin.com/BJ5tNQ2N

我在跑…

  • Ubuntu /特立独行(最新)
  • Python = 2.6.6
  • virtualenv = 1.5.1
  • gunicorn = 0.12.0
  • Django = 1.2.5
  • psycopg2 ='2.4-beta2(dt dec pq3 ext)'

gunicornconfiguration:

 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" 

supervisordconfiguration:

 [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 

有什么build议? 我一直坚持这一个。

这似乎是一些奇怪的内存限制,因为我没有执行任何特殊的事情:

 $ 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 

我跟踪了这​​个在davisp,一个gunicorn开发者的帮助下。 谢谢 !

这是一个环境问题,由导弹炮弹subprocess环境中的无效HOME设置引起的。

我没有得到任何东西,直到我把我的settings.py文件中的“import psycopg2”,它在监督器的gunderorn的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'" 

我在我的supervisorconfiguration文件中为gunicorn添加了以下行,现在Pythonfind了一个u +可写的蛋caching。 一切都好。

 environment=HOME='/home/hc'