feat(local): 启动器顺带拉起隧道 client,配了 tunnel/client.yml 才起

client 作为第 5 个子进程挂在启动器下,停止时由 do_cleanup 的 kill_tree 一并收掉,
所以不需要单独的 start/stop 脚本。它自带指数退避重连、进程不退出,也不需要有守护循环。

stop.sh 补一步兜底:启动器被 kill -9 时 EXIT trap 不跑,client 会漏成孤儿,
按它自己写的 tunnel.pid 收掉(正常路径读不到这个文件,do_cleanup 已删)。
This commit is contained in:
2026-11-15 12:27:39 +08:00
parent dab9d8f000
commit 0c9a92aabd
2 changed files with 21 additions and 1 deletions
+10 -1
View File
@@ -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
+11
View File
@@ -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