From 452728be32e0dee032aae585e72d0bc30b8b32f3 Mon Sep 17 00:00:00 2001 From: milky0217 Date: Mon, 15 Jun 2026 11:19:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20deploy.sh=E5=A2=9E=E5=8A=A0=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E7=8E=AF=E5=A2=83=E6=A3=80=E6=B5=8B-=E7=A6=81?= =?UTF-8?q?=E6=AD=A2=E7=9B=B4=E6=8E=A5=E9=83=A8=E7=BD=B2=E5=88=B0=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E6=B4=BB=E5=8A=A8=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.sh | 1 + lib/common.sh | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/deploy.sh b/deploy.sh index bebe316..85d2b6f 100755 --- a/deploy.sh +++ b/deploy.sh @@ -129,6 +129,7 @@ if [ "$ROLLBACK" = true ]; then rollback; exit 0; fi # ---------- 主部署流程 ---------- show_deploy_info confirm_deploy +check_not_active check_dependencies check_service_file check_ssl_expiry diff --git a/lib/common.sh b/lib/common.sh index b0e05fb..cb29bdf 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -106,6 +106,31 @@ check_service_file() { log_info "service 配置检查通过" } +# ---------- 蓝绿部署:检查目标是否为当前活动环境 ---------- +NGINX_CONTAINER="1Panel-openresty-ABu5" +ROOT_PROXY_CONF="/www/sites/xmclassmate.top/proxy/root.conf" + +check_not_active() { + [ -z "$BG_TARGET" ] && return 0 # 非蓝绿部署,跳过 + + local active_env + active_env=$(remote "docker exec ${NGINX_CONTAINER} cat ${ROOT_PROXY_CONF} 2>/dev/null" 2>/dev/null | grep -oP '127\.0\.0\.1:(4433|4434)' | head -1 || echo "") + + local current_target + case "$active_env" in + *4433) current_target="blue" ;; + *4434) current_target="green" ;; + *) current_target="unknown" ;; + esac + + if [ "$current_target" = "$BG_TARGET" ]; then + log_error "禁止部署: ${BG_TARGET} (:${BG_PORT}) 是当前活动环境" + log_error "请部署到待命环境: $( [ "$BG_TARGET" = "blue" ] && echo 'green' || echo 'blue' )" + exit 1 + fi + log_info "目标 ${BG_TARGET} 非活动环境(当前: ${current_target}),可以部署 ✅" +} + deploy_service_file() { log_step "部署 systemd service 文件..." [ "$DRY_RUN" = true ] && { log_dry "上传 $(get_service_file_local) → /etc/systemd/system/${SERVICE_NAME}"; return 0; }