This commit is contained in:
vet
2026-04-20 23:25:09 +07:00
parent ea6019311f
commit 4bd0efc8f5

View File

@@ -16,6 +16,15 @@ init_script_log # ← 脚本执行日志
FE_PROJECTS=(pc meetingh5 h5 cms build-cms build-down)
TARGET="${1:-all}"
declare -A FE_PORT_NUM=(
[pc]="5173"
[meetingh5]="5188"
[h5]="3003"
[cms]="8001"
[build-cms]="8002"
[build-down]="8003"
)
_stop_fe() {
local name="$1"
local pidfile="$PID_DIR/fe-${name}.pid"
@@ -36,6 +45,8 @@ _stop_fe() {
else
warn "$name 没有 PID 记录(未运行)"
fi
_stop_fe_port "$name"
}
_kill_tree() {
@@ -48,6 +59,37 @@ _kill_tree() {
kill "-$signal" "$pid" 2>/dev/null || true
}
_stop_fe_port() {
local name="$1"
local port="${FE_PORT_NUM[$name]}"
local pids pid
pids="$(lsof -tiTCP:"$port" -sTCP:LISTEN 2>/dev/null || true)"
if [[ -z "$pids" ]]; then
return 0
fi
warn "$name 端口 $port 仍被占用,按端口清理监听进程: $pids"
for pid in $pids; do
_kill_tree "$pid" TERM
done
sleep 1
for pid in $pids; do
if kill -0 "$pid" 2>/dev/null; then
_kill_tree "$pid" KILL
fi
done
pids="$(lsof -tiTCP:"$port" -sTCP:LISTEN 2>/dev/null || true)"
if [[ -n "$pids" ]]; then
error "$name 端口 $port 清理失败,仍被占用: $pids"
return 1
fi
success "$name 端口 $port 已释放"
}
if [[ "$TARGET" == "all" ]]; then
step "停止全部前端开发服务器"
for proj in "${FE_PROJECTS[@]}"; do