我不是 Unix 专家,并且在 Ubuntu 服务器 (20.04.5 LTS) 上的 Azure 上运行 WebApp 时遇到问题,gunicorn.service 不会创建 MyProjet.sock 文件。具体来说,WebApp 始终有效,从一天到第二天 MyProject.sock 文件被删除,我无法重新创建它。
我尝试遵循此处和 StackOverflow 上找到的几个解决方案,更准确地说是这个命令序列
sudo systemctl stop nginx
sudo systemctl stop gunicorn.service
sudo systemctl restart nginx
sudo systemctl daemon-reload
sudo systemctl restart gunicorn.service
sudo systemctl status gunicorn.service
我得到的结果如下
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2024-01-12 13:40:11 UTC; 1min 18s ago
Process: 2305577 ExecStart=/home/admin/myproject/backend/venv/bin/gunicorn --workers 3 --timeout 1800 --bind unix:/home/admin/myproject/backend/myproject.sock project.wsgi:application (code=exited, status=3)
Main PID: 2305577 (code=exited, status=3)
Jan 12 13:40:10 DeployUbuntu gunicorn[2305583]: Inner error: {
Jan 12 13:40:10 DeployUbuntu gunicorn[2305583]: "code": "ForbiddenByFirewall"
Jan 12 13:40:10 DeployUbuntu gunicorn[2305583]: }
Jan 12 13:40:10 DeployUbuntu gunicorn[2305583]: [2024-01-12 13:40:10 +0000] [2305583] [INFO] Worker exiting (pid: 2305583)
Jan 12 13:40:11 DeployUbuntu gunicorn[2305577]: [2024-01-12 13:40:11 +0000] [2305577] [WARNING] Worker with pid 2305584 was terminated due to signal 15
Jan 12 13:40:11 DeployUbuntu gunicorn[2305577]: [2024-01-12 13:40:11 +0000] [2305577] [WARNING] Worker with pid 2305583 was terminated due to signal 15
Jan 12 13:40:11 DeployUbuntu gunicorn[2305577]: [2024-01-12 13:40:11 +0000] [2305577] [INFO] Shutting down: Master
Jan 12 13:40:11 DeployUbuntu gunicorn[2305577]: [2024-01-12 13:40:11 +0000] [2305577] [INFO] Reason: Worker failed to boot.
Jan 12 13:40:11 DeployUbuntu systemd[1]: gunicorn.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Jan 12 13:40:11 DeployUbuntu systemd[1]: gunicorn.service: Failed with result 'exit-code'.
我注意到,如果我尝试通过连接命令来一次执行所有命令,则该服务似乎可以正常工作
sudo systemctl stop nginx && sudo systemctl stop gunicorn.service && sudo systemctl restart nginx && sudo systemctl daemon-reload && sudo systemctl restart gunicorn.service && sudo systemctl status gunicorn.service
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2024-01-12 13:40:10 UTC; 22ms ago
Main PID: 2305577 (gunicorn)
Tasks: 1 (limit: 9530)
Memory: 2.8M
CGroup: /system.slice/gunicorn.service
└─2305577 /home/admin/myproject/backend/venv/bin/python /home/admin/myproject/backend/venv/bin/gunicorn --workers 3 --timeout 1800 --bind unix:/home/admin/myproject/backend/myproject.sock project.wsgi>
Jan 12 13:40:10 DeployUbuntu systemd[1]: Started gunicorn daemon.
但如果我立即执行
sudo systemctl status gunicorn.service
它给了我上面指出的错误消息。
在我的古尼康服务
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=admin
Group=www-data
WorkingDirectory=/home/admin/myproject/backend
ExecStart=/home/admin/myproject/backend/venv/bin/gunicorn --workers 3 --timeout 1800 --bind unix:/home/admin/myproject/backend/myproject.sock project.wsgi:application
[Install]
WantedBy=multi-user.target
我想补充一点,我已经尝试卸载并重新安装gunicorn 和该项目。最后,我想补充一下,使用的gunicorn版本是20.1.0,这是由于项目规范所致。