为 gunicorn 创建 supervisord 脚本的正确方法?姜戈 1.6
Posted
技术标签:
【中文标题】为 gunicorn 创建 supervisord 脚本的正确方法?姜戈 1.6【英文标题】:Correct way of creating supervisord script for gunicorn? Django 1.6 【发布时间】:2013-02-10 08:59:18 【问题描述】:这是我的 gonicorn.conf,但我似乎无法正确获取命令。当我在命令行中键入时,我尝试的命令正在运行,但不是作为主管命令。
[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
【问题讨论】:
好的,请阅读:***.com/questions/14464533/… 并告诉我它是否有效 是的,这似乎可以解决问题。谢谢! 【参考方案1】:可以通过将此变量添加到您的设置文件来修复该特定错误。我在将 Django 项目从 Django 1.3 升级到 Django 1.5 时遇到了这个问题。 (更多信息请参见https://docs.djangoproject.com/en/dev/topics/logging/)
LOGGING =
'version': 1,
'disable_existing_loggers': True,
【讨论】:
【参考方案2】:[program:projectname_gunicorn_live]
command=/home/myusername/projectname-live/bin/django run_gunicorn -b 127.0.0.1:1559
directory=/home/myusername/projectname-live/
user=myusername
autostart=True
autorestart=True
redirect_stderr=True
链接:https://gist.github.com/oaksakal/1143612
另一个链接:Gunicorn Supervisor Startup Error
【讨论】:
我的 bin 文件夹中没有任何名为 django 的文件。我已经从 git 安装了 django。试图指向manage.py,但是当我尝试“manage.py run_gunicorn -b 127.0.0.1:1559”时出现此错误 ValueError: dictionary doesn't specify a version 您尝试了我的示例还是修改了它?我对此没有更多了解,但尝试运行上面的示例,只需更改 myusername 和 projectname 是的,我尝试了您的示例,但使用了我的用户名和项目名称。但是当我的 bin 文件夹中没有“django”文件时,我认为它不适用于我的设置。 好的,我将再次搜索它以寻找其他解决方案以上是关于为 gunicorn 创建 supervisord 脚本的正确方法?姜戈 1.6的主要内容,如果未能解决你的问题,请参考以下文章
CMDB之部署Django Nginx+Gunicorn+virtualenv+supervisord应用
使用 gunicorn 和 supervisord 将 django 部署到 CentOS 启动附加进程 django-admin.py
Django项目使用gunicorn+supervisor启动,生产环境适用