🐛 fix(deploy): 修复服务存在性检测误判导致服务未启动

- systemctl list-unit-files | grep -q 在 pipefail 下:grep -q 匹配后提前退出,
  systemctl 因 SIGPIPE 返回 141,管道整体判假,误走"服务不存在"分支
- 改用 systemctl cat 检测,无管道且不依赖输出格式
This commit is contained in:
chenxin committed 2026-10-09 15:58:55 +08:00
1 parent 889c399a0b
commit bf49805bb6
1 file changed
+3 -1
+3 -1
View File
@@ -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