fix: gunicorn.conf.py 从 sync 改为 gthread,修复全站卡死根因

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-09 05:07:06 +08:00
parent 5d20c1ed97
commit a48c9d3134
3 changed files with 56 additions and 39 deletions

37
deploy/audit-system.sh Normal file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
# 系统级排查Gunicorn 是否双开、是否用了错误的 sync 配置
set -e
echo "========== Gunicorn 进程(看 worker_class / 是否双开)=========="
pgrep -af gunicorn || echo "无 gunicorn"
echo ""
echo "========== 8001 端口占用 =========="
ss -ltnp 2>/dev/null | grep 8001 || netstat -ltnp 2>/dev/null | grep 8001 || echo "8001 未监听"
echo ""
echo "========== systemd 实际启动命令 =========="
systemctl cat gunicorn-dianjing.service 2>/dev/null | grep -E '^ExecStart|^Environment' || echo "无 systemd service"
echo ""
echo "========== gunicorn.conf.py 关键项 =========="
CONF="/opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django/gunicorn.conf.py"
if [ -f "$CONF" ]; then
grep -E 'worker_class|workers|threads|accesslog|errorlog|preload' "$CONF" | grep -v '^#'
else
echo "找不到 $CONF"
fi
echo ""
echo "========== 判定 =========="
NG=$(pgrep -cf 'gunicorn.*a_long_dianjing' 2>/dev/null || echo 0)
if [ "$NG" -gt 8 ]; then
echo ">>> 警告: gunicorn 进程过多($NG),可能 systemd + 1Panel 双开,必须只留 systemd"
fi
if grep -q 'worker_class.*sync' "$CONF" 2>/dev/null; then
echo ">>> 致命: gunicorn.conf.py 仍是 sync全站会卡死必须改为 gthread 并 restart"
fi
if grep -q 'accesslog.*"-' "$CONF" 2>/dev/null || grep -q "accesslog = '-'" "$CONF" 2>/dev/null; then
echo ">>> 致命: accesslog 输出到 stdout会灌 journal 卡整机"
fi
echo ""
echo "正确做法: 1Panel 关闭 Python 自动管理 → git pull → bash deploy/safe-deploy.sh"