Ubuntu

啟動 gunicorn.service 失敗:未找到單元 gunicorn.service。烏本托 18.04

  • March 24, 2020

我正在關注如何在 Ubuntu 18.04 指南上使用 Postgres、Nginx 和 Gunicorn 設置 Django。

我創建了以下文件 .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.

為了解決這個問題,我嘗試過

這修復了它:

sudo systemctl enable gunicorn.service

引用自:https://serverfault.com/questions/1008227