gunicorn 开机后不启动

gunicorn does not start after boot

我是 运行 一个带有 nginx 和 gunicorn 的 Debian 网络服务器 运行 一个 django 应用程序。我已经准备好一切,运行 很好,但在重新启动服务器后,我收到 502 错误网关错误。我已经将问题追溯到重启后 gunicorn 处于非活动状态。如果我启动服务,问题就会得到解决,直到我再次重新启动服务器。

正在启动服务:

systemctl start gunicorn.service

重启后这里是我的 gunicorn 服务状态:

{username}@instance-3:~$ sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled)
Active: inactive (dead)

我的 /etc/systemd/system/gunicorn.service 文件的内容:

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

[Service]
User={username}
Group={username}
WorkingDirectory=/home/{username}/web/{projname}
ExecStart=/usr/local/bin/gunicorn {projname}.wsgi:application
Restart=on-failure

[Install]
WantedBy=multi.user.target

有什么想法可以解决 gunicorn 服务在重启后无法启动的原因吗?

编辑:

问题可能是 gunicorn.conf 在 chdir 和 exec 中的目录与工作目录不同吗?

{username}@instance-3:~$ cat /etc/init/gunicorn.conf 
cription "Gunicorn application server handling {projname}"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid {username}
setgid {username}
chdir /home/data-reporting/draco_reporting

exec {projname}/bin/gunicorn --workers 3 --bind unix:/home/{username}/data-reporting/{projname}/{projname}.sock {projname}.wsgi:application

您的 gunicorn.service 文件中有一个小错字。更改为:

WantedBy=multi-user.target

此外,您可能想更改为:

Restart=always