linux - gunicorn ERROR(异常终止)

标签 linux django ubuntu amazon-ec2 gunicorn

我正在运行一个 fabric 脚本,除其他外,它应该在 ubuntu 服务器上重启 gunicorn,命令如下:

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

问题是,gunicorn 一开始似乎没有运行,所以无法终止进程,我通过 ssh 进入 amazon ec2 实例并运行

sudo supervisorctl restart projectname:gunicorn' 

我收到一条错误响应:

projectname:gunicorn: ERROR (not running) projectname:gunicorn ERROR (abnormal termination)

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

sudo supervisorctl start projectname:gunicorn

错误是

'projectname:gunicorn: Error (abnormal termination)'

所以我需要 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>

另外,这是配置文件

[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

有什么想法吗?我知道这是很多文字,任何提示或指针将不胜感激

感谢阅读,

编辑:

自行运行unicorn,激活虚拟环境并运行

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

还在虚拟环境中运行运行服务器:

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 用户与主管配置中的一组相匹配

编辑 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

我的设置在设置目录中,并且存在初始化文件,所以问题不在于此。 此外,应用程序在运行服务器上启动,因此设置文件必须是可导入的

最佳答案

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

OP 写道:

Solved the issue (I think)

as per the info in this link https://stackoverflow.com/a/19256794/2049067 , I added the project to the python path

export PYTHONPATH=:/my/path

then ran the gunicorn command again:

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

and gunicorn is up and running, and the site is accessible, I exited the ssh and everything is (seemingly) still working. I should also add that before I set the pythonpath I changed the ownerwhip on the gunicorn log:

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

Though I dont know if that helped

& seeing how the application has been running for years I dont know how the project was removed from the pythonpath

关于linux - gunicorn ERROR(异常终止),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21189525/

相关文章:

c - 为什么我的写入没有阻塞到这个管道?

python - django-rest-framework:如何序列化数据库模型的连接?

performance - 从源代码/从头开始编译 linux perf 工具及其依赖的内核模块

linux - 使用 U-Boot 从闪存上传固件

linux - 分离 ec2 实例的根卷

linux - 从 Matlab 启动应用程序

python - 连接mysql到Django-python

django - “WSGIRequest”对象在 django 4 中没有属性 'is_ajax'

java - 打开 pom.xml 时 Eclipse 编辑器不会打开

Ubuntu 12.10 Crontab 启动 Vino VNC Server