gunicorn.socket

gunicorn.socket

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

我的项目目录

  • djangoTest(MyTest Django 项目)
  • 管理.py
  • myvenv(我的 virtualEnv - 具有 gunicorn 和 Django 以及其他依赖项)
  • 静止的

Django测试树

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  

我正在使用以下教程进行相同的设置。[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]

当我使用以下命令启动 gunicorn 服务时

sudo systemctl status gunicorn.socket

我收到以下错误

**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.****

请帮忙!!

答案1

我现在可以解决这个问题了。我已在以下属性中更改了 gunicorn.service 文件中的配置。

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

相关内容