【问题标题】:Trying to configure gunicorn尝试配置 gunicorn
【发布时间】:2019-09-23 01:30:18
【问题描述】:

我一直在关注这个tutorial 在 Digital Ocean 上部署我的 django 项目。我正在尝试配置gunicorn

我的项目结构如下所示:

在我的settings.py 上,我使用DEBUG=False

我创建了 gunicorn.socket 和 gunicorn.service。

/etc/systemd/system/gunicorn.socket

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

/etc/systemd/system/gunicorn.service

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=someuser
Group=www-data
WorkingDirectory=/home/someuser/myproject
ExecStart=/home/someuser/myproject/myprojectenv/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          Myproject.wsgi:application

[Install]
WantedBy=multi-user.target

我启动并启用 Gunicorn 套接字:

sudo systemctl start gunicorn.socket 
sudo systemctl enable gunicorn.socket

检查进程的状态以确定它是否能够启动:

sudo systemctl status gunicorn.socket

这是我得到的,然后它返回到命令行。

Failed to dump process list, ignoring: No such file or directory
β—� gunicorn.socket - gunicorn socket
   Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
   Active: active (listening) since Sat 2019-05-04 23:12:03 UTC; 13s ago
   Listen: /run/gunicorn.sock (Stream)
   CGroup: /system.slice/gunicorn.socket

May 04 23:12:03 myproject systemd[1]: Listening on gunicorn socket.

接下来,我检查 /run 目录中是否存在 gunicorn.sock 文件:

file /run/gunicorn.sock
/run/gunicorn.sock: socket

文件或目录似乎不存在,但没有提供更多详细信息。 gunicorn.sock 似乎存在。

我熟悉 Python,但不熟悉服务器和部署,所以我在这里不知所措。

几个月前我已经成功地遵循了 Ubuntu 16.04 的类似教程,但现在我一直遇到问题。

【问题讨论】:

    标签: python django gunicorn


    【解决方案1】:

    这实际上是您使用systemd 的问题。您需要在对systemctl 的调用中引用服务的名称,而不是您正在执行的套接字。在您的情况下,该服务将被称为 gunicorn,因为您已将 systemd 单元文件命名为 gunicorn.service

    systemctl enable gunicorn
    systemctl start gunicorn
    

    【讨论】:

    • 您知道如何获取有关错误的更多详细信息:“无法转储进程列表,忽略:没有这样的文件或目录”?
    【解决方案2】:

    我知道,这是个老问题,但是... 我有一些错误。在我的情况下,使用 modul wsgi 的 WorkingDirectory 和应用程序是错误的。我认为这是“myproject.wsgi:application”中的错误

    【讨论】:

      猜你喜欢
      • 2016-01-04
      • 1970-01-01
      • 2020-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-06
      • 2012-05-18
      • 2016-04-20
      相关资源
      最近更新 更多