为gunicorn创建supervisord脚本的正确方式是什么?Django 1.6

4

这是我的gonicorn.conf文件,但我似乎无法正确执行命令。当我在命令行中输入该命令时可以正常工作,但在Supervisor命令中却不行。

[program:gunicorn]
directory = /home/USER/.virtualenvs/SITE/myApp/
command=/home/USER/.virtualenvs/SITE/bin/python /home/USER/.virtualenvs/SITE/myApp/manage.py run_gunicorn myApp.wsgi:application -c /home/USER/.virtualenvs/SITE/myApp/gunicorn.conf.py
user = USER
autostart = true
autorestart = true
redirect_stderr = true
stdout_logfile = /home/USER/logs/gunicorn.log
stderr_logfile = /home/USER/logs/gunicorn_err.log

什么是正确的gunicorn命令?

当我尝试启动gunicorn时,这里是我得到的错误:

/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/sorl/thumbnail/helpers.py:5: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.
  from django.utils import simplejson

2013-02-25 13:46:55 [3975] [INFO] Starting gunicorn 0.17.2
2013-02-25 13:46:55 [3975] [INFO] Listening at: http://127.0.0.1:8000 (3975)
2013-02-25 13:46:55 [3975] [INFO] Using worker: sync
2013-02-25 13:46:55 [3988] [INFO] Booting worker with pid: 3988
2013-02-25 13:46:55 [3988] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
    worker.init_process()
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
    self.callable = self.load()
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 133, in load
    return mod.make_command_wsgi_application(self.admin_media_path)
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 113, in make_command_wsgi_application
    reload_django_settings()
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 109, in reload_django_settings
    logging_config_func(settings.LOGGING)
  File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/lib/python2.7/logging/config.py", line 503, in configure
    raise ValueError("dictionary doesn't specify a version")
ValueError: dictionary doesn't specify a version
Traceback (most recent call last):
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
    worker.init_process()
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
    self.callable = self.load()
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 133, in load
    return mod.make_command_wsgi_application(self.admin_media_path)
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 113, in make_command_wsgi_application
    reload_django_settings()
  File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 109, in reload_django_settings
    logging_config_func(settings.LOGGING)
  File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/lib/python2.7/logging/config.py", line 503, in configure
    raise ValueError("dictionary doesn't specify a version")
ValueError: dictionary doesn't specify a version 

1
好的,请阅读这个链接:http://stackoverflow.com/questions/14464533/gunicorn-supervisor-startup-error,告诉我是否有效。 - catherine
是的,那似乎解决了问题。谢谢! - Tomas Jacobsen
2个回答

22

将此变量添加到您的设置文件中即可解决该特定错误。我在将Django1.3 项目升级到Django1.5时遇到了这个问题。 (更多信息请参见https://docs.djangoproject.com/en/dev/topics/logging/)。

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
}

0

我的bin文件夹里没有叫做django的文件。我是从git上安装的django。尝试指向manage.py,但是当我尝试运行"manage.py run_gunicorn -b 127.0.0.1:1559"时,出现了以下错误:ValueError: 字典未指定版本。 - Tomas Jacobsen
你试过我的示例了吗,还是改过它了?我对此没有更多的知识,但请尝试运行上面的示例,只需更改myusername和projectname。 - catherine
是的,我尝试了你的示例,但是使用我的用户名和项目名称。但是,当我bin文件夹中没有“django”文件时,我不认为它会在我的设置上起作用。 - Tomas Jacobsen
好的,我会再搜索一下,寻找另一个解决方案。 - catherine

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接