我正在尝试将Django应用程序部署到DigitalOcean droplet上。 我创建了一个systemd服务,在启动时启动gunicorn。
这是我的配置文件:(/etc/systemd/system/gunicorn.service)
这是我的配置文件:(/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时,出现以下错误信息: Failed to start gunicorn.service: Unit gunicorn.socket not found.
我检查了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" 命令创建套接字文件,但没有成功。
我仔细检查了文件和目录名称,没有错误。
我该如何解决这个问题?