From 776d31833065019717487b5418752c0d81183547 Mon Sep 17 00:00:00 2001 From: milky0217 Date: Mon, 15 Jun 2026 11:00:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20deploy.sh=E8=AE=BE=E7=BD=AE400=E7=A7=92?= =?UTF-8?q?=E8=B6=85=E6=97=B6+=E6=94=AF=E4=BB=98=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=85=A8=E9=9D=A2=E5=AE=A1=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 14cf603..b0e05fb 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -10,6 +10,9 @@ log_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; } log_step() { echo -e "${BLUE}[STEP]${NC} $1"; } log_dry() { echo -e "${YELLOW}[DRY-RUN]${NC} $1"; } +# 默认超时(秒) +: "${DEPLOY_TIMEOUT_SEC:=400}" + # ---------- Git 信息 ---------- get_git_info() { local b=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") @@ -23,10 +26,11 @@ get_ssh_socket() { echo "/tmp/ssh-master-${REMOTE_HOST}-$$"; } ssh_connect() { [ "$DRY_RUN" = true ] && { log_dry "ssh -o ControlMaster=auto -o ControlPath=$(get_ssh_socket) ${REMOTE_USER}@${REMOTE_HOST}"; return 0; } local socket; socket=$(get_ssh_socket) - if ! ssh -o "ControlPath=${socket}" -o "ConnectionAttempts=3" -o "ConnectTimeout=10" \ + # 测试连接 + if ! timeout "${DEPLOY_TIMEOUT_SEC}" ssh -o "ControlPath=${socket}" -o "ConnectionAttempts=3" -o "ConnectTimeout=10" \ -o "ControlMaster=no" "${REMOTE_USER}@${REMOTE_HOST}" "echo ok" &>/dev/null; then log_info "建立 SSH 连接..." - ssh -o ControlMaster=auto -o ControlPath="${socket}" -o ControlPersist=600 \ + timeout "${DEPLOY_TIMEOUT_SEC}" ssh -o ControlMaster=auto -o ControlPath="${socket}" -o ControlPersist=600 \ -o ConnectionAttempts=3 -o ConnectTimeout=10 \ -N "${REMOTE_USER}@${REMOTE_HOST}" & sleep 2 @@ -41,7 +45,7 @@ ssh_disconnect() { } # SSH 快捷执行(复用 ControlMaster) -remote() { ssh -o "ControlPath=$(get_ssh_socket)" "${REMOTE_USER}@${REMOTE_HOST}" "$@"; } +remote() { timeout "${DEPLOY_TIMEOUT_SEC}" ssh -o "ConnectTimeout=10" -o "ServerAliveInterval=30" -o "ControlPath=$(get_ssh_socket)" "${REMOTE_USER}@${REMOTE_HOST}" "$@"; } # ---------- 部署日志 ---------- get_deploy_log() { echo "${REMOTE_DIR}/deploy.log"; }