From ff8ba91b8da5e5f4d54618c107139adbb112e9d7 Mon Sep 17 00:00:00 2001 From: WanWanYun Date: Thu, 13 Nov 2025 12:16:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E6=9B=B4=E6=8D=A2=E6=97=B6=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=80=80=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题描述: - 部署时后端端口被占用,用户更换其他端口后脚本异常退出 - 根因: health_check()函数中netstat命令失败时触发set -e导致脚本退出 修复内容: 1. 端口检查添加错误抑制 (2>/dev/null) 2. 添加ss命令作为netstat的fallback 3. Nginx状态检查直接通过目录检测BT Panel环境 4. 修复变量作用域问题 (IS_BT_PANEL仅在局部函数中定义) 技术细节: - netstat -tunlp 2>/dev/null || ss -tunlp 2>/dev/null - 使用 [[ -d /www/server/nginx ]] 直接检测宝塔面板 - 宝塔环境使用pgrep检查nginx进程 - 标准环境使用systemctl is-active检查 影响范围: - health_check() 函数 (install.sh:2588-2612) - 提升脚本在端口冲突场景下的健壮性 - 兼容宝塔面板和标准Nginx环境 --- install.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index f3481bd..a460730 100644 --- a/install.sh +++ b/install.sh @@ -2585,7 +2585,7 @@ health_check() { fi # 检查端口 - if netstat -tunlp | grep -q ":${BACKEND_PORT}"; then + if netstat -tunlp 2>/dev/null | grep -q ":${BACKEND_PORT}" || ss -tunlp 2>/dev/null | grep -q ":${BACKEND_PORT}"; then print_success "后端端口监听正常 (${BACKEND_PORT})" else print_error "后端端口监听异常" @@ -2593,11 +2593,22 @@ health_check() { fi # 检查Nginx - if systemctl is-active --quiet nginx; then - print_success "Nginx服务运行正常" + if [[ -d /www/server/nginx ]]; then + # 宝塔面板:检查进程 + if pgrep -x nginx > /dev/null; then + print_success "Nginx服务运行正常" + else + print_error "Nginx服务异常" + return 1 + fi else - print_error "Nginx服务异常" - return 1 + # 标准Nginx:使用systemctl检查 + if systemctl is-active --quiet nginx; then + print_success "Nginx服务运行正常" + else + print_error "Nginx服务异常" + return 1 + fi fi # 检查数据库