【问题标题】:How to fix "Failed to restart gunicorn.service: Unit gunicorn.socket not found." error?如何解决“无法重新启动 gunicorn.service:未找到单元 gunicorn.socket。”错误?
【发布时间】:2021-11-08 05:48:32
【问题描述】:

我正在尝试将 django 应用程序部署到 DigitalOcean 液滴。我创建了一个 systemd 服务来启动 gunicorn。

这是我的配置文件:(/etc/systemd/system/gunicorn.service)

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

[Service]
User=root
Group=www-data
Environment="DJANGO_SETTINGS_MODULE=core.settings.production"
WorkingDirectory=/home/myproject-api/src
ExecStart=/home/myproject-api/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock core.wsgi:application

[Install]
WantedBy=multi-user.target

当我直接在终端上运行“ExecStart”行时,它可以工作。但是我无法启动 gunicorn 服务。

当我尝试启动 gunicorn 时出现此错误: 启动 gunicorn.service 失败:未找到单元 gunicorn.socket。

我检查了 gunicorn 可执行文件,它存在:

test -f /home/myproject-api/env/bin/gunicorn && echo "Gunicorn exists."

我可以使用gunicorn --bind 0.0.0.0:8000 core.wsgicommand 运行服务器。当我这样运行时,我可以使用服务器的 IP 地址访问服务器。

通常,当我启动服务器时应该创建套接字文件。我还尝试使用“touch /run/gunicorn.sock”创建套接字文件,但没有成功。

我仔细检查了文件和目录名称。没有错。

我该如何解决这个问题?

【问题讨论】:

    标签: django ubuntu gunicorn


    【解决方案1】:

    我通过创建/etc/systemd/system/gunicorn.socket 文件解决了这个问题:

    [Unit]
    Description=gunicorn socket
    
    [Socket]
    ListenStream=/run/gunicorn.sock
    
    [Install]
    WantedBy=sockets.target
    

    在 Ubuntu 20 中,我们必须创建这个文件来运行 gunicorn 服务。

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 2017-04-04
      • 2021-10-26
      • 2021-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-02
      • 2019-08-20
      相关资源
      最近更新 更多