nex_docus/scripts/stop.sh

37 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
#
# 停止由 scripts/start.sh 启动的本地开发服务。
#
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
RUN_DIR="${PROJECT_DIR}/.run"
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
stop_pid_file() {
local file="$1" label="$2"
[ -f "$file" ] || return 0
local pid
pid="$(cat "$file")"
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
# 连同子进程一起结束(npm / uvicorn --reload 会派生子进程)
pkill -TERM -P "$pid" 2>/dev/null || true
kill -TERM "$pid" 2>/dev/null || true
echo -e "${GREEN}✓${NC} 已停止 ${label} (pid ${pid})"
else
echo -e "${YELLOW}!${NC} ${label} 未在运行"
fi
rm -f "$file"
}
stop_pid_file "${RUN_DIR}/backend.pid" "后端服务"
stop_pid_file "${RUN_DIR}/frontend.pid" "前端服务"
# 兜底:清理没有 pid 文件却仍在监听的 vite(只匹配本项目路径,不会误伤其它项目)
pkill -f "${PROJECT_DIR}/frontend/node_modules" 2>/dev/null \
&& echo -e "${YELLOW}!${NC} 清理了残留的前端进程" || true
echo "完成。"