简体   繁体   中英

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

I am following this How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 18.04 guide.

I have created the following file .socket

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

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

I have created the following file .service

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

Original RECOMENDED_FORMATTING-s in the guide

[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

How I have formatted my own version I had my virtual environment outside of the project folder on the server

[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

I have also tried leaving these as originally recommended

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

Than I have tried to execute the following code

sudo systemctl start gunicorn

error message 1

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

and I have also tried with 2

sudo systemctl start gunicorn.socket

Error message 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.

To solve this, I have tried

这修复了它:

sudo systemctl enable gunicorn.service

It cost me about three hours ... Fxxx

Don't do this:

  sudo systemctl start gunicorn.socket
  sudo systemctl enable gunicorn.socket

Do this:

  sudo systemctl enable gunicorn.socket
  sudo systemctl start gunicorn.socket

and:

  sudo systemctl status gunicorn.socket

it works fine now !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM