gpt4 book ai didi

django - 如何修复 "Failed to restart gunicorn.service: Unit gunicorn.socket not found."错误?

转载 作者:行者123 更新时间:2023-12-04 18:26:13 25 4
gpt4 key购买 nike

我正在尝试将 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.wsgi 运行服务器命令。当我这样运行时,我可以使用服务器的 IP 地址访问服务器。
通常,应该在我启动服务器时创建套接字文件。我还尝试使用“touch/run/gunicorn.sock”创建套接字文件,但没有成功。
我仔细检查了文件和目录名称。没有错误。
我怎么解决这个问题?

最佳答案

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

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target
在 Ubuntu 20 中,我们必须创建这个文件来运行 gunicorn 服务。

关于django - 如何修复 "Failed to restart gunicorn.service: Unit gunicorn.socket not found."错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69154138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com