Revert "chore(deploy): run next with pm2"

This reverts commit 0bca7d4fa7.
This commit is contained in:
2026-06-18 17:36:45 +08:00
parent e5eaf6fa41
commit 2b45237ea6
+7 -50
View File
@@ -18,7 +18,6 @@ REPO_TOPLEVEL=""
LOG_FILE="" LOG_FILE=""
CURRENT_BRANCH="" CURRENT_BRANCH=""
START_PORT="" START_PORT=""
PM2_APP_NAME=""
BUILD_EXIT=0 BUILD_EXIT=0
STOP_WAIT_SECONDS=3 STOP_WAIT_SECONDS=3
STOP_VERIFY_RETRIES=3 STOP_VERIFY_RETRIES=3
@@ -88,21 +87,16 @@ select_port_by_branch() {
case "$CURRENT_BRANCH" in case "$CURRENT_BRANCH" in
main) main)
START_PORT=9185 START_PORT=9185
PM2_APP_NAME="cozsweet-main"
;; ;;
test|dev) test|dev)
START_PORT=9135 START_PORT=9135
PM2_APP_NAME="cozsweet-$CURRENT_BRANCH"
;; ;;
*) *)
START_PORT=9135 START_PORT=9135
PM2_APP_NAME="cozsweet-$CURRENT_BRANCH"
;; ;;
esac esac
export START_PORT export START_PORT
export PM2_APP_NAME
echo "=== start port: $START_PORT ===" >> "$LOG_FILE" echo "=== start port: $START_PORT ===" >> "$LOG_FILE"
echo "=== pm2 app: $PM2_APP_NAME ===" >> "$LOG_FILE"
} }
# ============================================================ # ============================================================
@@ -194,41 +188,11 @@ stop_existing_next() {
return 0 return 0
} }
stop_existing_pm2() {
echo "=== stop existing pm2 app $PM2_APP_NAME @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
if ! command -v pm2 >/dev/null 2>&1; then
echo "=== pm2 command not found; install pm2 before deployment ===" >> "$LOG_FILE"
return 1
fi
if pm2 describe "$PM2_APP_NAME" >/dev/null 2>&1; then
pm2 delete "$PM2_APP_NAME" >> "$LOG_FILE" 2>&1 || true
echo "=== pm2 app deleted: $PM2_APP_NAME ===" >> "$LOG_FILE"
else
echo "=== no pm2 app found: $PM2_APP_NAME ===" >> "$LOG_FILE"
fi
echo "" >> "$LOG_FILE"
return 0
}
launch_next() { launch_next() {
echo "=== pm2 LAUNCH app=$PM2_APP_NAME port=$START_PORT @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE" echo "=== start LAUNCH port=$START_PORT @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
PORT="$START_PORT" nohup pnpm run start >> "$LOG_FILE" 2>&1 &
export PORT="$START_PORT" START_PID=$!
pm2 start pnpm --name "$PM2_APP_NAME" -- run start >> "$LOG_FILE" 2>&1 echo "=== start PID=$START_PID @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
PM2_EXIT=$?
echo "=== pm2 START EXIT_CODE=$PM2_EXIT @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
if [ "$PM2_EXIT" -ne 0 ]; then
echo "=== pm2 START FAILED ===" >> "$LOG_FILE"
return "$PM2_EXIT"
fi
pm2 save >> "$LOG_FILE" 2>&1 || true
echo "=== realtime logs: pm2 logs $PM2_APP_NAME ===" >> "$LOG_FILE"
return 0
} }
# ============================================================ # ============================================================
@@ -256,17 +220,10 @@ main() {
exit $BUILD_EXIT # build 失败 → 不启 start(避免用旧 .next 跑新代码) exit $BUILD_EXIT # build 失败 → 不启 start(避免用旧 .next 跑新代码)
fi fi
if ! stop_existing_pm2; then if ! stop_existing_next; then
exit 1 # pm2 不可用 → 不启动新服务 exit 1 # 端口未释放 → 不启动新服务,避免 EADDRINUSE
fi
# if ! stop_existing_next; then
# exit 1 # 端口未释放 → 不启动新服务,避免 EADDRINUSE
# fi
if ! launch_next; then
exit 1 # pm2 启动失败
fi fi
launch_next # 再启新
} }
main "$@" main "$@"