deploy: 安全部署脚本,清理实验配置由仓库脚本负责
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,28 +1,6 @@
|
||||
#!/bin/bash
|
||||
# 部署卡顿修复并验证 rt=
|
||||
# 兼容旧名:转 safe-deploy + 清理实验配置
|
||||
set -e
|
||||
DJANGO_DIR="/opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django"
|
||||
NGINX_LOG="/opt/1panel/apps/openresty/nginx/log/access.log"
|
||||
cd "$DJANGO_DIR"
|
||||
|
||||
echo ">>> git pull"
|
||||
git pull origin main
|
||||
|
||||
echo ">>> 更新 systemd (6 workers)"
|
||||
cp deploy/systemd/gunicorn-dianjing.service /etc/systemd/system/gunicorn-dianjing.service
|
||||
systemctl daemon-reload
|
||||
systemctl restart gunicorn-dianjing.service
|
||||
sleep 2
|
||||
systemctl is-active gunicorn-dianjing.service
|
||||
pgrep -cf 'gunicorn.*a_long_dianjing' || true
|
||||
|
||||
echo ""
|
||||
echo ">>> 最近慢请求 (rt>=0.5s):"
|
||||
grep -a 'hqhd' "$NGINX_LOG" | awk 'match($0,/rt=([0-9.]+)/,a){if(a[1]+0>=0.5)print}' | tail -5
|
||||
|
||||
echo ""
|
||||
echo ">>> 最近 dddhq / merchant-staff/me:"
|
||||
grep -a 'hqhd' "$NGINX_LOG" | grep -E 'ddhq|merchant-staff/me' | tail -8 | awk 'match($0,/rt=([0-9.]+)/,a){rt=a[1]} match($0,/POST ([^ ]+)/,b){print " rt="rt"s "b[1]}'
|
||||
|
||||
echo ""
|
||||
echo "部署完成。请用手机再试,然后看上面 rt 是否都 <0.2s"
|
||||
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
bash "$DIR/cleanup-lag-experiments.sh" 2>/dev/null || true
|
||||
bash "$DIR/safe-deploy.sh"
|
||||
|
||||
24
deploy/cleanup-lag-experiments.sh
Normal file
24
deploy/cleanup-lag-experiments.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
# 仅撤销「排查实验」加的配置(cron 保活、慢请求追踪 override)
|
||||
# 由仓库脚本执行,不需要你手动 rm 任何路径
|
||||
set -e
|
||||
DJANGO_DIR="/opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django"
|
||||
cd "$DJANGO_DIR"
|
||||
|
||||
if [ -f /etc/cron.d/gunicorn-warmup ]; then
|
||||
if grep -q 'gunicorn-warmup.sh' /etc/cron.d/gunicorn-warmup 2>/dev/null; then
|
||||
echo ">>> 移除本仓库安装的 cron 保活"
|
||||
rm -f /etc/cron.d/gunicorn-warmup
|
||||
else
|
||||
echo ">>> 跳过 cron(非本仓库创建的文件)"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f /etc/systemd/system/gunicorn-dianjing.service.d/slow-trace.conf ]; then
|
||||
echo ">>> 关闭慢请求追踪 override"
|
||||
rm -f /etc/systemd/system/gunicorn-dianjing.service.d/slow-trace.conf
|
||||
systemctl daemon-reload
|
||||
systemctl restart gunicorn-dianjing.service
|
||||
fi
|
||||
|
||||
echo "清理完成。"
|
||||
25
deploy/safe-deploy.sh
Normal file
25
deploy/safe-deploy.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
# 安全部署:只 git pull + 更新 systemd + 重启,不手动删任何路径
|
||||
# 用法: bash deploy/safe-deploy.sh
|
||||
set -e
|
||||
DJANGO_DIR="/opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django"
|
||||
cd "$DJANGO_DIR"
|
||||
|
||||
echo ">>> git pull"
|
||||
git pull origin main
|
||||
|
||||
echo ">>> 更新 gunicorn systemd"
|
||||
cp deploy/systemd/gunicorn-dianjing.service /etc/systemd/system/gunicorn-dianjing.service
|
||||
systemctl daemon-reload
|
||||
systemctl enable gunicorn-dianjing.service
|
||||
systemctl restart gunicorn-dianjing.service
|
||||
sleep 2
|
||||
|
||||
echo ">>> 状态"
|
||||
systemctl is-active gunicorn-dianjing.service
|
||||
echo "gunicorn 进程: $(pgrep -cf 'gunicorn.*a_long_dianjing' || echo 0)"
|
||||
|
||||
echo ""
|
||||
echo "部署完成。未删除任何文件。"
|
||||
echo "若需查卡顿根因(可选): bash deploy/enable-slow-trace.sh"
|
||||
echo "查完关闭追踪: bash deploy/disable-slow-trace.sh"
|
||||
Reference in New Issue
Block a user