gunicorn状态是活动的(已退出)但显示未在监视中运行

时间:2016-11-17 04:45:34

标签: python linux django gunicorn init

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

如果我手动运行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' 

1 个答案:

答案 0 :(得分:2)

我刚刚向我发出了同样的错误消息(您是否也在关注数字海洋教程?)并花了相当长的时间试图解决这个问题。我不知道你是否仍然需要它,但也许我可以让别人浪费尽可能多的时间。

我设法通过以下方式修复它(经过几次不同的尝试):

  1. 停止枪声:

    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符号链接:

    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

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

    OBS:我的文件名为gunicorn.service,我认为是默认文件。我更改为gunicorn-project.service以符合OP的术语。