Reputation: 3096
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
systemctl status gunicorn.socket
Result: Warning: The unit file, source configuration file or drop-ins of gunicorn.socket changed on disk
● gunicorn.socket - gunicorn daemon
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
systemctl is-enabled gunicorn.socket
Result: enabled
systemctl is-enabled gunicorn.service
Result: Failed to get unit file state for gunicorn.service: No such file or directory
Upvotes: 0
Views: 6292
Reputation: 51
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 !
Upvotes: 5