Failing to Start gunicorn.service using systemd

7,926

I am able to resolve this issue now. I have changed configurations in the gunicorn.service file in the below properties.

WorkingDirectory=~/Python-Projects to /root/Python-Projects

Share:
7,926

Related videos on Youtube

Srinivas Nani
Author by

Srinivas Nani

Updated on September 18, 2022

Comments

  • Srinivas Nani
    Srinivas Nani over 1 year

    gunicorn.socket

    [Unit]  
    Description=gunicorn socket
    
    [Socket]  
    ListenStream=/run/gunicorn.sock
    
    [Install]  
    WantedBy=sockets.target  
    

    gunicorn.service

    [Unit]  
    Description=gunicorn daemon
    Requires=gunicorn.socket
    After=network.target
    
    [Service]    
    PIDFile=/run/gunicorn/pid  
    
    User=ubuntu  
    
    Group=www-data  
    
    RuntimeDirectory=gunicorn  
    
    WorkingDirectory=~/Python-Projects  
    
    ExecStart=~/Python-Projects/myvenv/bin/gunicorn \  
              --access-logfile ~/Python-Projects/djangoTest/logs/djangoTest.access.log \  
              --error-logfile ~/Python-Projects/djangoTest/logs/djangoTest.error.log \  
              --pid /run/gunicorn/pid   \  
              --env DJANGO_SETTINGS_MODULE=djangoTest.settings.production \  
              --bind unix:/run/gunicorn.sock \  
              djangoTest.wsgi:application
    
    ExecReload=/bin/kill -s HUP $MAINPID  
    
    ExecStop=/bin/kill -s TERM $MAINPID  
    
    PrivateTmp=true  
    
    
    [Install]    
    WantedBy=multi-user.target
    

    My Project Directory

    • djangoTest(MyTest Django Project)
    • manage.py
    • myvenv(My virtualEnv - has gunicorn and Django and other dependencies)
    • static

    DjangoTest Tree

    djangoTest  
    ├── __init__.py  
    ├── __pycache__  
    │   ├── __init__.cpython-36.pyc  
    │   ├── settings.cpython-36.pyc  
    │   ├── urls.cpython-36.pyc  
    │   └── wsgi.cpython-36.pyc  
    ├── settings.py  
    ├── urls.py  
    └── wsgi.py  
    

    I am using the below tutorial for setting up the same. [https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04#creating-systemd-socket-and-service-files-for-gunicorn][1]

    When I am starting the gunicorn service using below command

    sudo systemctl status gunicorn.socket

    I am getting the below error

    **Jan 03 06:01:47 ip-# systemd[1]: **gunicorn.socket: Socket service gunicorn.service not loaded, refusing.**  
    Jan 03 06:01:47 ip-# systemd[1]: **Failed to listen on gunicorn socket.  
    root@ip-#:/etc/systemd/system# Jan 03 04:56:52 ip-# systemd[1]: Failed to listen on gunicorn socket.****
    

    PLEASE HELP!!

  • Kalob Taulien
    Kalob Taulien over 4 years
    Results in a formatting error. Failed to restart gunicorn.service: Unit gunicorn.service is not loaded properly: Exec format error. It's caused by the ~