gunicorn 停止查找 wsgi 目录

gunicorn 停止查找 wsgi 目录

我使用 nginx gunicorn 和 Supervisor 配置了一个 django 应用。几个月来一切都运行良好,直到今天。我没有触碰任何配置文件,但不知何故,502 bad gateway当我尝试访问我网站的任何页面时,我现在得到了响应。

Gunicorn 此处出现错误,以下是其输出的日志:

Traceback (most recent call last):
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/workers/ggevent.py", line 162, in init_process
    super().init_process()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
    self.load_wsgi()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    return self.load_wsgiapp()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
    mod = importlib.import_module(module)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'inventory4'

我非常困惑,因为之前一切都运行顺利!

这里是我的 gunicorn 的 django 配置:

设置.py:

WSGI_APPLICATION = 'inventory4.wsgi.application'

在 wsgi.py 中:

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'inventory4.settings')

application = get_wsgi_application()

这是我在 /etc/supervisor/conf.d/gunicorn.conf 中的内容

directory=/home/ubuntu/exostocksaas
command=/home/ubuntu/exo/bin/gunicorn  --config /home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/config.py --log-level debug --bind unix:/home/ubuntu/exostocksaas/app.sock inventory4.wsgi:application

autostart=true
autorestart=true
stderr_logfile=/var/log/gunicorn/gunicorn.err.log
stdout_logfile=/var/log/gunicorn/gunicorn.out.log


[group:guni]
programs:gunicorn

这是 gunicorn 包中的 config.py 文件:

BASE_DIR = "/home/ubuntu/"
sys.path.append(BASE_DIR)
 
 
bind = '127.0.0.1:8000'
backlog = 2048
 
 
import multiprocessing
daemon: True
workers = 20
worker_class = 'gevent'
worker_connections = 1000
timeout = 300
graceful_timeout = 300
keepalive = 300
inactivity_timeout=300
errorlog = '-'
loglevel = 'info'
accesslog = '-'
threads = 2

老实说,我刚刚对 django 应用程序进行了更新,所以这很奇怪,有谁知道或经历过可能导致此问题的事情吗?

我现在想到的可能是我的虚拟机遇到了加载问题,这会导致 gunicorn 崩溃吗?以下是我运行时注意到的landscape-sysinfo

System load:  9.56              Processes:           135
  Usage of /:   80.7% of 7.69GB   Users logged in:     1
  Memory usage: 38%               IP address for eth0: xxx.xx.xx.xx
  Swap usage:   0%

这可能是问题所在吗?

答案1

我找到了一个解决方案,以防有人发现她,免责声明 ^^ 我无法解释为什么它停止工作以及为什么解决方案解决了这个问题。 gunicorn 日志中显示的错误似乎是一种默认问题,而真正的问题却没有出现。我怀疑这是一个 CPU 问题。

我只是去了 /venv/lib/python3.6/site-packages/gunicorn/config.conf 并添加了

threads = 2

它之前被设置为 1,现在将其设置为 2 就可以了。我非常乐意接受任何更好的修复,或者解释为什么它解决了这个问题。

相关内容