• /etc/systemd/system/gunicorn.socket

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

    /etc/systemd/system/gunicorn.service

    [Unit]
    Description=gunicorn daemon
    Requires=gunicorn.socket
    After=network.target
    
    [Service]
    User=root
    Group=nobody
    WorkingDirectory=/root/myprojectdir
    ExecStart=/root/myprojectdir/myprojectenv/bin/gunicorn \
              --access-logfile - \
              --workers 3 \
              --log-level debug \
              --bind unix:/run/gunicorn.sock \
              myproject.wsgi:application
    
    
    [Install]
    WantedBy=multi-user.target
    
    systemctl start gunicorn.socket
    systemctl enable gunicorn.socket

    修改systemd文件后需要

    systemctl daemon-reload