Fix PM2 startup: run only the sudo line from pm2 startup output.

Avoid executing PM2 banner text as shell commands during install.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-28 12:55:55 +08:00
parent 521a0fc66f
commit 9f34ce8e07
+13 -4
View File
@@ -171,6 +171,18 @@ setup_gateway() {
npm ci
}
setup_pm2_startup() {
log_info "配置 PM2 开机自启…"
local startup_cmd
startup_cmd=$(pm2 startup systemd -u root --hp /root 2>&1 | grep -E '^sudo ' | tail -1 || true)
if [[ -n "${startup_cmd}" ]]; then
# shellcheck disable=SC2086
eval ${startup_cmd} || log_warn "PM2 开机自启配置失败,可稍后手动执行: pm2 startup"
else
log_warn "未获取 PM2 startup 命令,重启后需手动 pm2 resurrect"
fi
}
start_pm2() {
log_info "启动 PM2 服务…"
cd "${INSTALL_DIR}"
@@ -178,10 +190,7 @@ start_pm2() {
pm2 delete grade-api grade-web 2>/dev/null || true
pm2 start deploy/pm2/ecosystem.config.cjs
pm2 save
env PATH="$PATH" pm2 startup systemd -u root --hp /root >/tmp/pm2-startup.sh 2>/dev/null || true
if [[ -f /tmp/pm2-startup.sh ]]; then
bash /tmp/pm2-startup.sh || true
fi
setup_pm2_startup
}
wait_healthy() {