无法启动 gunicorn.service:未找到单元 gunicorn.service。Ubunto 18.04

无法启动 gunicorn.service:未找到单元 gunicorn.service。Ubunto 18.04

我正在关注如何在 Ubuntu 18.04 上安装 Django 和 Postgres、Nginx 和 Gunicorn 指南。

我已经创建了以下文件 .socket

sudo nano /etc/systemd/system/gunicorn.socket

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

我已经创建了以下文件 .service

sudo nano /etc/systemd/system/gunicorn.service

原始 RECOMENDED_FORMATTING-s 在指导

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


[Service]
User=sammyRECOMENDED_FORMATTING
Group=www-data
WorkingDirectory=/home/sammyRECOMENDED_FORMATTING/myprojectdirRECOMENDED_FORMATTING
ExecStart=/home/sammyRECOMENDED_FORMATTING/myprojectdirRECOMENDED_FORMATTING/myprojectenvRECOMENDED_FORMATTING/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          myprojectRECOMENDED_FORMATTING.wsgi:application

[Install]
WantedBy=multi-user.target

我如何格式化我自己的版本我的虚拟环境位于服务器上的项目文件夹之外

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

[Service]
User=SERVER_USER
Group=www-data
WorkingDirectory=/home/SERVER_USER/MAIN_PROJECT_FOLDER
ExecStart=/home/SERVER_USER/ven/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/home/SERVER_USER/MAIN_PROJECT_FOLDER/MAINAPPLICATION_FOLDER.sock \
          MAINAPPLICATION_FOLDER.wsgi:application

[Install]
WantedBy=multi-user.target

我也尝试过按照最初的建议保留这些

--bind unix:/run/gunicorn.sock \

然后我尝试执行以下代码

sudo systemctl start gunicorn

错误消息 1

Failed to start gunicorn.service: Unit gunicorn.service not found.

我也尝试过 2

sudo systemctl start gunicorn.socket

错误消息 2

Failed to start gunicorn.socket: Unit gunicorn.socket is not loaded properly: Invalid argument.
See system logs and 'systemctl status gunicorn.socket' for details.

为了解决这个问题,我尝试过

答案1

这修复了它:

sudo systemctl enable gunicorn.service

相关内容