fix(deploy): force stop existing next service
This commit is contained in:
+30
-18
@@ -12,6 +12,7 @@ LOG_FILE=""
|
|||||||
CURRENT_BRANCH=""
|
CURRENT_BRANCH=""
|
||||||
START_PORT=""
|
START_PORT=""
|
||||||
BUILD_EXIT=0
|
BUILD_EXIT=0
|
||||||
|
STOP_WAIT_SECONDS=3
|
||||||
|
|
||||||
resolve_repo_context() {
|
resolve_repo_context() {
|
||||||
GIT_DIR_ABS="$(git rev-parse --absolute-git-dir 2>/dev/null)"
|
GIT_DIR_ABS="$(git rev-parse --absolute-git-dir 2>/dev/null)"
|
||||||
@@ -104,31 +105,42 @@ run_build() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 6. stop_existing_next —— 仅停止当前分支端口上的旧进程
|
# 6. stop_existing_next —— 强杀当前分支端口上的旧进程
|
||||||
# 1) 优雅关闭(SIGTERM)—— 旧进程自己 drain
|
# 1) 查找占用 START_PORT 的进程
|
||||||
# 2) 等 2s
|
# 2) 直接 SIGKILL,避免旧服务 drain 太久导致新服务无法绑定端口
|
||||||
# 3) 强杀(SIGKILL)—— 还在的话
|
# 3) 等待 STOP_WAIT_SECONDS,让系统释放端口
|
||||||
# 4) 等 1s
|
# 4) 复查端口占用并再次强杀残留
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
find_port_pids() {
|
||||||
|
if command -v lsof >/dev/null 2>&1; then
|
||||||
|
lsof -ti tcp:"$START_PORT" 2>/dev/null || true
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if command -v fuser >/dev/null 2>&1; then
|
||||||
|
fuser "$START_PORT"/tcp 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
stop_existing_next() {
|
stop_existing_next() {
|
||||||
echo "=== stop existing next on port $START_PORT @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
echo "=== stop existing next on port $START_PORT @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
||||||
PIDS=""
|
PIDS="$(find_port_pids)"
|
||||||
if command -v lsof >/dev/null 2>&1; then
|
|
||||||
PIDS="$(lsof -ti tcp:"$START_PORT" 2>/dev/null || true)"
|
|
||||||
elif command -v fuser >/dev/null 2>&1; then
|
|
||||||
PIDS="$(fuser "$START_PORT"/tcp 2>/dev/null || true)"
|
|
||||||
else
|
|
||||||
pkill -f "next start.*$START_PORT" 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$PIDS" ]; then
|
if [ -n "$PIDS" ]; then
|
||||||
kill $PIDS 2>/dev/null || true
|
echo "=== force kill PIDS: $PIDS ===" >> "$LOG_FILE"
|
||||||
fi
|
|
||||||
sleep 2
|
|
||||||
if [ -n "$PIDS" ]; then
|
|
||||||
kill -9 $PIDS 2>/dev/null || true
|
kill -9 $PIDS 2>/dev/null || true
|
||||||
|
else
|
||||||
|
echo "=== no process found on port $START_PORT ===" >> "$LOG_FILE"
|
||||||
fi
|
fi
|
||||||
sleep 1
|
|
||||||
|
sleep "$STOP_WAIT_SECONDS"
|
||||||
|
|
||||||
|
REMAINING_PIDS="$(find_port_pids)"
|
||||||
|
if [ -n "$REMAINING_PIDS" ]; then
|
||||||
|
echo "=== force kill remaining PIDS: $REMAINING_PIDS ===" >> "$LOG_FILE"
|
||||||
|
kill -9 $REMAINING_PIDS 2>/dev/null || true
|
||||||
|
sleep "$STOP_WAIT_SECONDS"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "=== stop DONE @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
echo "=== stop DONE @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
||||||
echo "" >> "$LOG_FILE"
|
echo "" >> "$LOG_FILE"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ export function ChatScreen() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UrlLauncherUtil.openUrlWithExternalBrowser(ROUTES.chat);
|
UrlLauncherUtil.openUrlWithExternalBrowser(ROUTES.splash);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
import { BrowserDetector } from "@/utils/browser-detect";
|
import { BrowserDetector } from "@/utils/browser-detect";
|
||||||
|
import { AppEnvUtil } from "@/utils/app-env";
|
||||||
import { SpAsyncUtil } from "@/utils/storage";
|
import { SpAsyncUtil } from "@/utils/storage";
|
||||||
import { pwaUtil } from "@/utils/pwa";
|
import { pwaUtil } from "@/utils/pwa";
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ export function PwaInstallOverlay() {
|
|||||||
// 提前挂 beforeinstallprompt 监听,避免用户点 OK 时事件已在更早时机丢失。
|
// 提前挂 beforeinstallprompt 监听,避免用户点 OK 时事件已在更早时机丢失。
|
||||||
pwaUtil.prepareInstallPrompt();
|
pwaUtil.prepareInstallPrompt();
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === "development";
|
const isDev = AppEnvUtil.isDevelopment();
|
||||||
|
|
||||||
if (!isDev) {
|
if (!isDev) {
|
||||||
// 生产环境:每日只弹一次(防骚扰)
|
// 生产环境:每日只弹一次(防骚扰)
|
||||||
|
|||||||
Reference in New Issue
Block a user