AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 669416
Accepted
JK Laiho
JK Laiho
Asked: 2015-02-18 13:40:53 +0800 CST2015-02-18 13:40:53 +0800 CST 2015-02-18 13:40:53 +0800 CST

gunicorn 19.2 无法以 18.0 配置启动

  • 772

我有一个在 nginx 后面运行 gunicorn/Django 的开发服务器。作为更广泛的服务器环境更新的一部分,我尝试将 gunicorn 从 18.0 升级到 19.2.1,但该服务将不再启动。(服务器正在运行 Arch,因此使用 systemctl。)

gunicorn 配置是由不再由我们支配的人完成的,并且不太了解 gunicorn,我无法修复甚至定位问题,所以我恢复到版本 18.0,它现在可以工作。但是,我想最终对其进行升级,并将配置设置为可以正常工作的形状。我感觉当前的配置不是最理想的或多余的,但我无法确定:-)。

环境(或 gunicorn 运行的 virtualenv)没有任何变化,只有 gunicorn 本身被升级。Systemctl 产生了这个错误systemctl start gunicorn:

● gunicorn.service - gunicorn daemon (production)
   Loaded: loaded (/usr/lib/systemd/system/gunicorn.service; enabled)
   Active: failed (Result: resources) since Tue 2015-02-17 20:55:41 UTC; 8s ago
  Process: 2837 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
  Process: 9608 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
  Process: 5353 ExecStart=/home/django/gunicorn/run.sh (code=exited, status=0/SUCCESS)
 Main PID: 24876 (code=exited, status=0/SUCCESS)

Feb 17 20:55:41 ashima systemd[1]: PID file /home/django/gunicorn/gunicorn.pid not readable (yet?) after start.
Feb 17 20:55:41 ashima systemd[1]: gunicorn.service never wrote its PID file. Failing.
Feb 17 20:55:41 ashima systemd[1]: Failed to start gunicorn daemon (production).
Feb 17 20:55:41 ashima systemd[1]: Unit gunicorn.service entered failed state.

尝试run.sh从 shell 手动运行包含在(粘贴在下面)中的 gunicorn 命令,它只是立即退出而没有产生任何错误,退出代码为 0。没有记录任何内容。事实上,看起来我的前任在日志文件增长到惊人的大小后不久就禁用了 gunicorn 日志记录,但这是另一天的问题。

以下是相关文件的内容:

/usr/lib/systemd/system/gunicorn.service:

[Unit]
Description=gunicorn daemon

[Service]
Type=forking
PIDFile=/home/django/gunicorn/gunicorn.pid
User=django
WorkingDirectory=/home/django/[name_withheld]/project
ExecStart=/home/django/gunicorn/run.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=false

[Install]
WantedBy=multi-user.target

/home/django/gunicorn/run.sh:

#!/bin/bash

set -e

cd /home/django/[name_withheld]/project
source /home/django/.venv/bin/activate
exec gunicorn -p /home/django/gunicorn/gunicorn.pid -c /home/django/gunicorn/config.py -e HTTPS=on [name_withheld]_site.wsgi:application

/home/django/gunicorn/config.py:

bind = 'unix:/tmp/gunicorn.sock'
backlog = 2048
workers = 16
worker_class = 'egg:gunicorn#sync'
worker_connections = 1000
timeout = 30
keepalive = 2
debug = False
spew = False
daemon = True
pidfile = None
umask = 0755
user = None
group = None
tmp_upload_dir = None
raw_env = 'HTTPS=on'
errorlog = '-'
loglevel = 'info'
accesslog = None
proc_name = None

def post_fork(server, worker):
    server.log.info("Worker spawned (pid: %s)", worker.pid)

def pre_fork(server, worker):
    pass

def pre_exec(server):
    server.log.info("Forked child, re-executing.")

def when_ready(server):
    server.log.info("Server is ready. Spawning workers")
arch-linux
  • 1 1 个回答
  • 1086 Views

1 个回答

  • Voted
  1. Best Answer
    JK Laiho
    2015-02-24T21:25:52+08:002015-02-24T21:25:52+08:00

    (在发布到问题的评论中,我必须特别指出skarap的评论,因为它通过使 gunicorn 正确输出错误帮助我自己找到解决方案。我希望我能为此奖励部分赏金;转换对答案的评论还不是一个完整的答案,但它确实有很大帮助。)

    原来这是配置文件中有问题的行:

    worker_class = 'egg:gunicorn#sync'

    它导致了这个错误:

    Error: class uri 'egg:gunicorn#sync' invalid or not found: 
    
    [Traceback (most recent call last):
      File "/home/django/.venv/lib/python2.7/site-packages/gunicorn/util.py", line 113, in load_class
        return pkg_resources.load_entry_point(dist, section, name)
      File "/home/django/.venv/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 318, in load_entry_point
        return get_distribution(dist).load_entry_point(group, name)
      File "/home/django/.venv/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2220, in load_entry_point
        raise ImportError("Entry point %r not found" % ((group,name),))
    ImportError: Entry point ('gunicorn.workers', 'sync') not found
    ]
    

    将其替换为worker_class = 'sync'修复了 ImportError 并因此解决了问题。在 18.0 -> 19.2.1 升级中不需要其他配置更改。

    我打算报告 gunicorn 的文档似乎存在问题,因为在撰写本文时,v19.2.1 的文档仍然声明egg:gunicorn#[worker]语法有效。(那里的示例使用 gevent,但它看起来应该适用于其他类型)。谁知道,它在某些情况下可能是有效的,但在我的(virtualenv 中的 gunicorn,用 pip 安装),它不是。

    • 1

相关问题

  • 哪个守护进程在archlinux中实现afp文件共享?

  • Arch Linux 不挂载两个 U 盘?

  • 从其他计算机访问 Webmin [关闭]

  • Arch Linux 上的 VPN 服务器

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve