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