-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop.sh
More file actions
executable file
·22 lines (19 loc) · 1.1 KB
/
Copy pathstop.sh
File metadata and controls
executable file
·22 lines (19 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env bash
# 停止 mcp-video-transcript:停 launchd 托管实例,并杀掉占用端口的"本程序"进程。别的程序不动。
set -uo pipefail
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LABEL="com.weft.video-transcript"
GUI="gui/$(id -u)"
PORT="$(sed -n 's/^[[:space:]]*port[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p' "$REPO/config.toml" 2>/dev/null | head -1)"
PORT="${PORT:-8010}"
port_pids() { lsof -nP -iTCP:"$PORT" -sTCP:LISTEN -t 2>/dev/null; }
proc_cwd() { lsof -a -p "$1" -d cwd -Fn 2>/dev/null | sed -n 's/^n//p' | head -1; }
is_ours() { [ "$(proc_cwd "$1")" = "$REPO" ] || ps -p "$1" -o command= 2>/dev/null | grep -q "$REPO"; }
echo "■ 停止 mcp-video-transcript(端口 $PORT)…"
launchctl bootout "$GUI/$LABEL" 2>/dev/null && echo " 已停 launchd 托管实例。"
for pid in $(port_pids); do
if is_ours "$pid"; then kill "$pid" 2>/dev/null && echo " 已杀本程序进程 PID $pid。"
else echo " 端口仍被其它程序占用(PID $pid),不动它。"; fi
done
sleep 1
[ -z "$(port_pids)" ] && echo "✅ 已停止。" || echo "⚠ 端口 $PORT 仍有监听(见上)。"