fix: switch-env.sh修复路径/协议/数据库名+添加SSH_HOST硬编码
This commit is contained in:
@@ -12,10 +12,12 @@ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|||||||
ENV_FILE="$PROJECT_ROOT/.env"
|
ENV_FILE="$PROJECT_ROOT/.env"
|
||||||
|
|
||||||
# ---------- 配置 ----------
|
# ---------- 配置 ----------
|
||||||
SSH_HOST="root@1panel-server"
|
# 1Panel 管理的 OpenResty 容器的实际配置文件路径
|
||||||
PROXY_DIR="/www/sites/xmclassmate.top/proxy"
|
BASE_DIR="/opt/1panel/apps/openresty/openresty"
|
||||||
|
PROXY_DIR="${BASE_DIR}/www/sites/xmclassmate.top/proxy"
|
||||||
ROOT_CONF="${PROXY_DIR}/root.conf"
|
ROOT_CONF="${PROXY_DIR}/root.conf"
|
||||||
NGINX_CONTAINER="1Panel-openresty-ABu5"
|
NGINX_CONTAINER="1Panel-openresty-ABu5"
|
||||||
|
SSH_HOST="root@1panel-server"
|
||||||
|
|
||||||
# ---------- 颜色输出 ----------
|
# ---------- 颜色输出 ----------
|
||||||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
|
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
|
||||||
@@ -62,7 +64,7 @@ show_status() {
|
|||||||
echo " 绿色 :4434 $( [ "$active" = "green" ] && echo '★ 活动中' || echo '○ 待命中' )"
|
echo " 绿色 :4434 $( [ "$active" = "green" ] && echo '★ 活动中' || echo '○ 待命中' )"
|
||||||
echo ""
|
echo ""
|
||||||
echo " 反向代理: xmclassmate.top"
|
echo " 反向代理: xmclassmate.top"
|
||||||
echo " 数据库: milkydata_dev"
|
echo " 数据库: milkydata (blue/green) / milkydata_dev (dev)"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# 检查两个端口是否可达
|
# 检查两个端口是否可达
|
||||||
@@ -92,16 +94,19 @@ switch_to() {
|
|||||||
|
|
||||||
# 先验证目标环境健康
|
# 先验证目标环境健康
|
||||||
echo "验证目标环境健康..."
|
echo "验证目标环境健康..."
|
||||||
local target_ok; target_ok=$(ssh "$SSH_HOST" "curl -s -o /dev/null -w '%{http_code}' --max-time 3 http://127.0.0.1:${target_port}/health" 2>/dev/null || echo "000")
|
local proto="http"; [ "$target_port" = "4433" ] && proto="https"
|
||||||
|
local extra=""; [ "$proto" = "https" ] && extra="-k"
|
||||||
|
local target_ok; target_ok=$(ssh "$SSH_HOST" "curl -s -o /dev/null -w '%{http_code}' --max-time 3 ${proto}://127.0.0.1:${target_port}/health ${extra}" 2>/dev/null || echo "000")
|
||||||
if [ "$target_ok" != "200" ]; then
|
if [ "$target_ok" != "200" ]; then
|
||||||
error "目标环境 :${target_port} 健康检查失败 (HTTP $target_ok),取消切换"
|
error "目标环境 :${target_port} 健康检查失败 (HTTP $target_ok),取消切换"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
info "目标环境健康 ✅"
|
info "目标环境健康 ✅"
|
||||||
|
|
||||||
# 修改 proxy_pass
|
# 修改 proxy_pass(根据端口自动选择 http/https)
|
||||||
info "修改 OpenResty proxy_pass → :${target_port}..."
|
local target_proto="http"; [ "$target_port" = "4433" ] && target_proto="https"
|
||||||
ssh "$SSH_HOST" "docker exec ${NGINX_CONTAINER} sh -c \"sed -i 's|proxy_pass http://127.0.0.1:[0-9]*|proxy_pass http://127.0.0.1:${target_port}|' ${ROOT_CONF}\"" 2>&1 || {
|
info "修改 OpenResty proxy_pass → ${target_proto}://127.0.0.1:${target_port}..."
|
||||||
|
ssh "$SSH_HOST" "docker exec ${NGINX_CONTAINER} sh -c \"sed -i 's|proxy_pass https\?://127.0.0.1:[0-9]*|proxy_pass ${target_proto}://127.0.0.1:${target_port}|' ${ROOT_CONF}\"" 2>&1 || {
|
||||||
error "修改 proxy_pass 失败"
|
error "修改 proxy_pass 失败"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user