Gunicorn状态为活动(退出),但显示未在监视器中运行



我正在尝试从头开始在服务器上设置一个新的django项目(django+gunicorn+nginx),除了gunicorn的初始化脚本外,我的一切都是正确的。

如果我手动运行gunicorn命令,它可以工作,我可以在ip地址上查看我的网站,但是当我尝试做service gunicorn start时,它给我这个输出,它不工作…

gunicorn-project.service
   Loaded: loaded (/etc/init.d/gunicorn-project; bad; vendor preset: enabled)
   Active: active (exited) since Thu 2016-11-17 04:23:56 UTC; 17min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1656 ExecStart=/etc/init.d/gunicorn-project start (code=exited, status=0/SUCCESS)
    Tasks: 0
   Memory: 0B
      CPU: 0
Nov 17 04:23:56 project gunicorn-project[1656]:   from multiprocessing import cpu_count
Nov 17 04:23:56 project gunicorn-project[1656]: /etc/gunicorn.d/gunicorn-project2.py:3: RuntimeWarning: Parent module '/
Nov 17 04:23:56 project gunicorn-project[1656]:   from os import environ
Nov 17 04:23:56 project gunicorn-project[1656]: /etc/gunicorn.d/gunicorn-project3.py:2: RuntimeWarning: Parent module '
Nov 17 04:23:56 project gunicorn-project[1656]:   from multiprocessing import cpu_count
Nov 17 04:23:56 project gunicorn-project[1656]: /etc/gunicorn.d/gunicorn-project3.py:3: RuntimeWarning: Parent module '
Nov 17 04:23:56 project gunicorn-project[1656]:   from os import environ
Nov 17 04:23:56 project gunicorn-project[1656]:  *
Nov 17 04:23:56 project systemd[1]: Started gunicorn-project.service.
Nov 17 04:25:01 project systemd[1]: Started gunicorn-project.service.

我不明白为什么会发生这种情况…

"""gunicorn WSGI server configuration."""
from multiprocessing import cpu_count
from os import environ

def max_workers():
    return cpu_count() * 2 + 1
max_requests = 1000
worker_class = 'gevent'
workers = max_workers()
errorlog = '/home/gunicorn-project/log/gunicorn/error.log'
accesslog = '/home/gunicorn-project/log/gunicorn/access.log' 

我刚刚遇到了同样的错误信息(你是否也遵循了Digital Ocean教程?),并花了几个小时试图弄清楚它。我不知道你是否还需要它,但也许我可以让别人不像我那样浪费那么多时间。

我设法修复它(经过几次不同的尝试):

  1. 停止gunicorn:

    sudo systemctl stop gunicorn

  2. 修改包含gunicorn.service的两个目录的写权限:

    sudo chmod u+x /etc/systemd/system/multi-user.target.wants/gunicorn-project.service

    sudo chmod u+x /etc/systemd/system/gunicorn-project.service

  3. 手动删除和重建gunicorn-project.service符号link:

    unlink /etc/systemd/system/multi-user.target.wants/gunicorn-project.service

    rm /etc/systemd/system/multi-user.target.wants/gunicorn-project.service

    ln -s /etc/systemd/system/gunicorn-project.service /etc/systemd/system/multi-user.target.wants/gunicorn-project.service

  4. 重新加载gunicorn守护进程:

    sudo systemctl daemon-reload

  5. 重启gunicorn:

    sudo systemctl start gunicorn

    sudo systemctl enable gunicorn

状态变为active (running)。基本上,在某些时候,我没有设置适当的权限就安装了gunicorn。一旦我用正确的权限重新执行了这些步骤,gunicorn就能够按预期执行了。

OBS:我的文件被命名为gunicorn.service,我相信这是默认的。我改成了gunicorn-project.service来匹配OP的术语。

最新更新