【发布时间】: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”创建套接字文件,但没有成功。
我仔细检查了文件和目录名称。没有错。
我该如何解决这个问题?
【问题讨论】: