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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user