Files
Django/deploy/final-fix-all.sh

82 lines
2.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 最终一次性修复(只跑这一个,不要其它脚本)
# 解决8001 双开、gunicorn sync、全局限流、DB 连接打满
set -e
DJANGO_DIR="/opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django"
LOG="/opt/1panel/apps/openresty/nginx/log/access.log"
cd "$DJANGO_DIR"
echo "=============================================="
echo " 星阙最终修复 $(date '+%H:%M:%S')"
echo "=============================================="
echo ""
echo "[1/6] 拉最新代码"
git fetch origin
git reset --hard origin/main
echo " 当前: $(git log -1 --oneline)"
echo ""
echo "[2/6] 检查全局限流是否已移除"
if grep -q 'DEFAULT_THROTTLE_CLASSES' a_long_dianjing/settings.py; then
echo " 失败: 仍有限流配置"
exit 1
fi
echo " OK: 无全局限流"
echo ""
echo "[3/6] 清掉所有 gunicorn释放 8001"
systemctl stop gunicorn-dianjing.service 2>/dev/null || true
sleep 2
pkill -f 'gunicorn' 2>/dev/null || true
sleep 3
if ss -ltn 2>/dev/null | grep -q ':8001'; then
fuser -k 8001/tcp 2>/dev/null || true
sleep 2
fi
echo ""
echo "[4/6] 只启动 systemd 唯一一套 (gthread 4x2)"
cp deploy/systemd/gunicorn-dianjing.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable gunicorn-dianjing.service
systemctl start gunicorn-dianjing.service
sleep 4
echo ""
echo "[5/6] 验证"
NG=$(pgrep -cf 'gunicorn.*a_long_dianjing' 2>/dev/null || echo 0)
RT=$(curl -s -o /dev/null -w '%{time_total}' --max-time 5 http://127.0.0.1:8001/hqhd/ 2>/dev/null || echo FAIL)
echo " gunicorn 进程: $NG (正常=5: 1master+4worker)"
echo " curl 8001: ${RT}s"
grep -q 'worker_class = "gthread"' gunicorn.conf.py && echo " gunicorn.conf: gthread OK"
venv/bin/python -c "import app_secrets; print(' 数据库:', app_secrets.DATABASE_HOST, app_secrets.DATABASE_PORT)"
REC429=$(grep -a 'hqhd' "$LOG" 2>/dev/null | tail -200 | awk '$9==429' | wc -l)
echo " 最近200条429: $REC429 (部署后应趋近0)"
echo ""
echo "[6/6] 测本机 Docker 数据库(若 OK 可改 app_secrets 治本)"
venv/bin/python -c "
import pymysql, app_secrets as s
try:
c=pymysql.connect(host='172.17.0.15',port=3306,user=s.DATABASE_USER,password=s.DATABASE_PASSWORD,database=s.DATABASE_NAME,connect_timeout=3)
c.close()
print(' 172.17.0.15:3306 可连 → 改 app_secrets DATABASE_HOST=172.17.0.15 PORT=3306 后 bash deploy/safe-deploy.sh')
except Exception as e:
print(' 172.17.0.15 不可连:', e)
" 2>/dev/null || echo " 跳过 Docker 库测试"
echo ""
echo "=============================================="
if [ "$NG" -le 6 ] && [ "$RT" != "FAIL" ]; then
echo " 系统层: 通过"
else
echo " 系统层: 仍有问题,把本输出全部贴给开发者"
fi
echo ""
echo " 【必做】1Panel 关闭 Python 自动管理,否则还会抢 8001"
echo " 然后手机再试。还卡 = 远程库 gvsds.com:50030 慢,需改本机库"
echo "=============================================="