设置 gunicorn 与 systemd 一起运行

Sam*_*uri 3 django gunicorn digital-ocean

试图设置gunicorn运行systemd。控制文件是/etc/systemd/system/gunicorn.service,测试的输出是

root@samuel-pc:~# systemctl start gunicorn
Failed to start gunicorn.service: Unit gunicorn.service is not loaded properly: Invalid argument.
See system logs and 'systemctl status gunicorn.service' for details.


root@samuel-pc:~# systemctl status gunicorn.service
? gunicorn.service - gunicorn daemon
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

Jun 29 05:13:17 samuel-pc systemd[1]: [/etc/systemd/system/gunicorn.service:9] Executable path is not absolute, ignoring: gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp
Jun 29 05:13:17 samuel-pc systemd[1]: gunicorn.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jun 29 05:13:29 samuel-pc systemd[1]: [/etc/systemd/system/gunicorn.service:9] Executable path is not absolute, ignoring: gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp
Jun 29 05:13:29 samuel-pc systemd[1]: gunicorn.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jun 29 05:15:45 samuel-pc systemd[1]: [/etc/systemd/system/gunicorn.service:9] Executable path is not absolute, ignoring: gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp
Jun 29 05:15:45 samuel-pc systemd[1]: gunicorn.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jun 29 07:01:10 samuel-pc systemd[1]: [/etc/systemd/system/gunicorn.service:9] Executable path is not absolute, ignoring: gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp
Jun 29 07:01:10 samuel-pc systemd[1]: gunicorn.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jun 29 07:01:55 samuel-pc systemd[1]: [/etc/systemd/system/gunicorn.service:9] Executable path is not absolute, ignoring: gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp
Jun 29 07:01:55 samuel-pc systemd[1]: gunicorn.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Run Code Online (Sandbox Code Playgroud)

这显示错误从 gunicorn 服务的第 9 行开始,因为 ExecStart

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

[Service]
User=root
Group=www-data
WorkingDirectory=/root/revamp
ExecStart=gunicorn --access-logfile - --workers 3 --bind unix:/root/revamp/revamp.sock revamp.wsgi:application


[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

Has*_*nPy 8

它告诉您它不需要gunicorn可执行文件的相对路径:
Executable path is not absolute, ignoring.

您需要将其更改为gunicorn可执行文件的绝对路径,或者:

  • 系统的可执行文件: ExecStart=/usr/local/bin/gunicorn
  • 您的虚拟环境的可执行文件: ExecStart=/path/to/venv/bin/gunicorn

您可以查看以下要点:使用Systemd 确保 Gunicorn在启动时启动,以获得最小的 Gunicorn systemd 服务配置文件。

希望这可以帮助!