From 0c9a92aabd18370c3ff0ff37f814b0385acf048e Mon Sep 17 00:00:00 2001 From: kicer Date: Sun, 15 Nov 2026 12:27:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(local):=20=E5=90=AF=E5=8A=A8=E5=99=A8?= =?UTF-8?q?=E9=A1=BA=E5=B8=A6=E6=8B=89=E8=B5=B7=E9=9A=A7=E9=81=93=20client?= =?UTF-8?q?=EF=BC=8C=E9=85=8D=E4=BA=86=20tunnel/client.yml=20=E6=89=8D?= =?UTF-8?q?=E8=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit client 作为第 5 个子进程挂在启动器下,停止时由 do_cleanup 的 kill_tree 一并收掉, 所以不需要单独的 start/stop 脚本。它自带指数退避重连、进程不退出,也不需要有守护循环。 stop.sh 补一步兜底:启动器被 kill -9 时 EXIT trap 不跑,client 会漏成孤儿, 按它自己写的 tunnel.pid 收掉(正常路径读不到这个文件,do_cleanup 已删)。 --- local/start.sh | 11 ++++++++++- local/stop.sh | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/local/start.sh b/local/start.sh index fc247c1..a175adb 100755 --- a/local/start.sh +++ b/local/start.sh @@ -795,7 +795,7 @@ kill_tree_hard() { do_cleanup() { # 心跳子进程也得收掉,不然退出后它会继续每秒重绘页面。 ui_stop_ticker - rm -f "$RUNTIME/ui/busy" "$RUNTIME/supervisor.pid" "$RUNTIME/preview.port" + rm -f "$RUNTIME/ui/busy" "$RUNTIME/supervisor.pid" "$RUNTIME/preview.port" "$RUNTIME/tunnel.pid" for p in $CORE_PID $MCP_PIDS; do kill_tree "$p"; done CORE_PID='' MCP_PIDS='' @@ -1126,6 +1126,15 @@ while :; do else say '技能:python3 未安装(Python 技能暂不可用)' fi + # 隧道 client(可选):配了 tunnel/client.yml 才起,当第 5 个子进程, + # 停止时由 do_cleanup 的 kill_tree 一并收掉。它自带指数退避重连、进程不退出, + # 所以不需要守护循环;日志也只报状态变化,连不上时静默重试。 + if [ -f "$ROOT/tunnel/client.yml" ]; then + ( cd "$ROOT/tunnel" && exec node client.js >>"$RUNTIME/tunnel.log" 2>&1 ) & + MCP_PIDS="$MCP_PIDS $!" + printf '%s\n' "$!" > "$RUNTIME/tunnel.pid" + say '隧道:已启动' + fi if [ "$FIRST_RUN" = 1 ]; then printf '\n首次使用:左下角「用户区」→ 设置 → 模型池,添加平台和 API Key,然后点「重启」。\n' fi diff --git a/local/stop.sh b/local/stop.sh index f1c4beb..12d9bd7 100755 --- a/local/stop.sh +++ b/local/stop.sh @@ -98,6 +98,17 @@ for p in "$PORT" $MCP_PORTS "$pv_port"; do done done +# 5) 隧道 client:它不监听端口,正常随启动器的 do_cleanup 一起收掉; +# 启动器被 kill -9 时 EXIT trap 不跑,会漏成孤儿,按它自己写的 pid 文件兜底。 +if [ -f "$RUNTIME/tunnel.pid" ]; then + tpid=$(cat "$RUNTIME/tunnel.pid" 2>/dev/null || printf '') + case "$tpid" in ''|*[!0-9]*) tpid='';; esac + if [ -n "$tpid" ] && kill -0 "$tpid" 2>/dev/null; then + stop_pid "$tpid" '隧道 client' + fi + rm -f "$RUNTIME/tunnel.pid" +fi + if [ "$stopped" = 1 ]; then say '已停止' else