gunicorn ERROR(异常终止)

时间:2014-01-17 15:26:01

标签: linux django ubuntu amazon-ec2 gunicorn

即时运行一个结构脚本,其中包括应该在ubuntu服务器上重启gunicorn,命令如下:

supervisorctl status projectname:gunicorn | sed "s/.*[pid ]\([0-9]\+\)\,.*/\1/" | xargs kill -HUP

问题是,是不是枪炮似乎没有在第一个地方运行所以这个过程不能被杀死,我已经进入了亚马逊ec2实例并且跑了

sudo supervisorctl restart projectname:gunicorn' 

我得到一个错误回复,上面写着:

  

projectname:gunicorn:ERROR(未运行)   projectname:gunicorn ERROR(异常终止)

所以我试图通过运行来启动gunicorn

sudo supervisorctl start projectname:gunicorn

错误说

  

' projectname:gunicorn:错误(异常终止)'

所以我需要枪炮才能跑,而且我无法实现这个

我还检查了gunicorn日志和下面的文字,下面是相关的输出

2014-01-17 14:58:14 [12260] [INFO] Starting gunicorn 0.14.3
2014-01-17 14:58:14 [12260] [INFO] Listening at: http://127.0.0.1:9000 (12260)
2014-01-17 14:58:14 [12260] [INFO] Using worker: sync
2014-01-17 14:58:14 [12263] [INFO] Booting worker with pid: 12263
2014-01-17 14:58:14 [12264] [INFO] Booting worker with pid: 12264
2014-01-17 14:58:14 [12265] [INFO] Booting worker with pid: 12265
2014-01-17 14:58:14 [12266] [INFO] Booting worker with pid: 12266
2014-01-17 14:58:14 [12263] [INFO] Worker exiting (pid: 12263)
2014-01-17 14:58:14 [12264] [INFO] Worker exiting (pid: 12264)
2014-01-17 14:58:14 [12265] [INFO] Worker exiting (pid: 12265)
2014-01-17 14:58:14 [12266] [INFO] Worker exiting (pid: 12266)
Traceback (most recent call last):
File "/opt/screening/env/bin/gunicorn_django", line 9, in <module>
load_entry_point('gunicorn==0.14.3', 'console_scripts', 'gunicorn_django')()
File "/opt/compliance_engine/env/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 129, in run
DjangoApplication("%prog [OPTIONS] [SETTINGS_PATH]").run()
File "/opt/compliance_engine/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 129, in run
Arbiter(self).run()
File "/opt/compliance_engine/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 184, in run
self.halt(reason=inst.reason, exit_status=inst.exit_status)
File "/opt/compliance_engine/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 279, in halt
self.stop()
File "/opt/compliance_engine/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 327, in stop
self.reap_workers()
File "/opt/compliance_engine/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 413, in reap_workers
raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

另外,这是conf文件

[program:gunicorn]
command=/opt/screening/env/bin/gunicorn_django --pythonpath . ce.settings -w 4 --bind             127.0.0.1:9000
directory=/opt/screening/repository
user=www-data
autostart=true
autorestart=true
stdout_logfile=/opt/screening/logs/gunicorn.log
redirect_stderr=true

[program:celeryd]
command=/opt/screening/env/bin/python manage.py celeryd --autoscale=16,2 -E -l INFO --pidfile=/opt/screening/tmp/pids/celeryd.pid
directory=/opt/screening/repository
user=www-data
autostart=true
autorestart=true
stdout_logfile=/opt/screening/logs/celeryd.log
redirect_stderr=true

[program:celerybeat]
command=/opt/screening/env/bin/python manage.py celerybeat -l INFO --    schedule=/opt/screening/tmp/celerybeat-schedule --    pidfile=/opt/screening/tmp/pids/celerybeat.pid
directory=/opt/screening/repository
user=www-data
autostart=true
autorestart=true
stdout_logfile=/opt/screening/logs/celerybeat.log
redirect_stderr=true

[program:celerycam]
command=/opt/screening/env/bin/python manage.py celerycam --    pidfile=/opt/screening/tmp/pids/celerycam.pid
directory=/opt/screening/repository
user=www-data
autostart=true
autorestart=true
stdout_logfile=/opt/screening/logs/celerycam.log
redirect_stderr=true

[group:screening]
programs=gunicorn,celeryd,celerybeat,celerycam

任何想法?我知道这是很多文本,任何提示或指针都会非常感激

感谢阅读,

编辑:

单独运行独角兽,激活虚拟环境并运行

python manage.py run_gunicorn

终端打印下面的输出

2014-01-19 22:02:35 [14735] [INFO] Starting gunicorn 0.14.3
2014-01-19 22:02:35 [14735] [INFO] Listening at: http://127.0.0.1:8000 (14735)
2014-01-19 22:02:35 [14735] [INFO] Using worker: sync
2014-01-19 22:02:35 [14742] [INFO] Booting worker with pid: 14742

还在virtualenv中运行了运行服务器:

python manage.py runserver 7000
Validating models...

0 errors found
Django version 1.3, using settings 'ce.settings'
Development server is running at http://127.0.0.1:7000/
Quit the server with CONTROL-C.

所以没有明显的错误

编辑2:

已与其他几个人谈过此事,并建议查看gunicorn日志的权限,这里是:

-rw-rw-r-- 1 www-data ubuntu    3270504 2014-01-19 23:23 gunicorn.log

www-data用户匹配supervisor配置中的一个

编辑3:我再次运行了gunicorn命令,但这次添加了日志信息:

gunicorn_django --pythonpath . ce.settings -w 4 --bind             127.0.0.1:9000 --debug --log-level debug

并收到以下错误消息:

Traceback (most recent call last):
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 453, in spawn_worker
    worker.init_process()
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 99, in init_process
    self.wsgi = self.app.wsgi()
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 101, in wsgi
    self.callable = self.load()
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 87, in load
mod = util.import_module("gunicorn.app.django_wsgi")
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 18, in <module>
    from django.core.management.validation import get_validation_errors
  File "/opt/screening/env/local/lib/python2.7/site-packages/django/core/management/validation.py", line 3, in <module>
    from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation
  File "/opt/screening/env/local/lib/python2.7/site-packages/django/contrib/contenttypes/generic.py", line 6, in <module>
    from django.db import connection
  File "/opt/screening/env/local/lib/python2.7/site-packages/django/db/__init__.py", line 14, in <module>
    if not settings.DATABASES:
  File "/opt/screening/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/opt/screening/env/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/opt/screening/env/local/lib/python2.7/site-packages/django/conf/__init__.py", line 89, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'ce.settings' (Is it on sys.path?): No module named ce.settings

2014-01-20 09:14:22 [31830] [INFO] Worker exiting (pid: 31830)
Traceback (most recent call last):
  File "/opt/screening/env/bin/gunicorn_django", line 9, in <module>
load_entry_point('gunicorn==0.14.3', 'console_scripts', 'gunicorn_django')()
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 129, in run
    DjangoApplication("%prog [OPTIONS] [SETTINGS_PATH]").run()
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 129, in run
    Arbiter(self).run()
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 184, in run
    self.halt(reason=inst.reason, exit_status=inst.exit_status)
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 279, in halt
    self.stop()
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 327, in stop
    self.reap_workers()
  File "/opt/screening/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 413, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

所以看起来突出的信息是:

ImportError: Could not import settings 'ce.settings' (Is it on sys.path?): No module named ce.settings

我的设置在设置目录中,并且存在init文件,所以问题不在于此。 此外,应用程序在runserver上启动,因此设置文件必须是可导入的

1 个答案:

答案 0 :(得分:2)

(问题由OP在问题编辑中回答。转换为社区维基答案。请参阅Question with no answers, but issue solved in the comments (or extended in chat)

OP写道:

  

解决了问题(我认为)

     

根据此链接https://stackoverflow.com/a/19256794/2049067中的信息,我将项目添加到python路径

export PYTHONPATH=:/my/path
  

然后再次运行gunicorn命令:

gunicorn_django --pythonpath . ce.settings -w 4 --bind             127.0.0.1:9000 --debug --log-level debug
  

gunicorn启动并运行,网站可访问,我退出了ssh,一切(看似)仍然有效。我还应该补充一点,在我设置pythonpath之前,我更改了gunicorn日志中的所有者:

sudo chown -R www-data:www-data gunicorn.log
  

虽然我不知道这是否有帮助

     

&安培;看看应用程序已运行多年我不知道该项目是如何从pythonpath中删除的