From bf49805bb67c304d3c04193d8870e2783f6bd34f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=AD=86?= <2685475410@qq.com> Date: Fri, 9 Oct 2026 15:58:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(deploy):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9C=8D=E5=8A=A1=E5=AD=98=E5=9C=A8=E6=80=A7=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E8=AF=AF=E5=88=A4=E5=AF=BC=E8=87=B4=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=9C=AA=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - systemctl list-unit-files | grep -q 在 pipefail 下:grep -q 匹配后提前退出, systemctl 因 SIGPIPE 返回 141,管道整体判假,误走"服务不存在"分支 - 改用 systemctl cat 检测,无管道且不依赖输出格式 --- deploy.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index bca3589..ce00c16 100755 --- a/deploy.sh +++ b/deploy.sh @@ -167,7 +167,9 @@ cleanup_old_versions() { # 重启服务 + 验证 restart_and_verify() { log "重启 ${APP_NAME} 服务..." - if systemctl list-unit-files 2>/dev/null | grep -q "^${APP_NAME}.service"; then + # 注意:不要用 "list-unit-files | grep -q"——grep -q 提前退出会让 systemctl 收到 + # SIGPIPE,在 pipefail 下整条管道判假(unit 多的机器必踩),误报"服务不存在" + if systemctl cat "${APP_NAME}" >/dev/null 2>&1; then $SUDO systemctl restart "${APP_NAME}" $SUDO systemctl enable "${APP_NAME}" >/dev/null 2>&1 || true else