diff --git a/deploy/install.sh b/deploy/install.sh index 36816bf..0309f9d 100644 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -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() {