Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

feat(agentos): 网关按 ingress_virtual_ip 仅在持有 VIP 的节点启动

kaichengs7a620cd0a0c1
diff --git a/deploy/yuanrong/check_handler.sh b/deploy/yuanrong/check_handler.sh
index bd68001201..d2b35d9dbb 100755
--- a/deploy/yuanrong/check_handler.sh
+++ b/deploy/yuanrong/check_handler.sh
@@ -34,6 +34,28 @@ get_local_ip() {
echo "127.0.0.1"
}
+# 读取 config.yaml 的 ingress_virtual_ip(VIP)。gateway 监听端口统一绑定 VIP,
+# 使各服务对外可通过统一入口访问;无 VIP 配置时输出空串。
+_ingress_vip() {
+ local config_file="${HOME:-/root}/.agentos/deploy/config.yaml"
+ [ -f "${config_file}" ] || return 1
+ local py="python${DEPLOY_VARS["YR_PYTHON_VERSION"]:-3.11}" vip=""
+ if command -v "${py}" >/dev/null 2>&1 && "${py}" -c 'import yaml' >/dev/null 2>&1; then
+ vip=$("${py}" -c '
+import sys, yaml
+try:
+ with open(sys.argv[1]) as f:
+ cfg = yaml.safe_load(f)
+ print((cfg or {}).get("cluster", {}).get("ingress_virtual_ip", "") or "", end="")
+except Exception:
+ print("", end="")
+' "${config_file}" 2>/dev/null)
+ fi
+ if [ -n "${vip}" ] && echo "${vip}" | grep -qE '^([0-9]{1,3}\.){3}[0-9]{1,3}$'; then
+ echo "${vip}"
+ fi
+}
+
check_cmds() {
for cmd in python3 jq; do
check_cmd ${cmd}
@@ -113,10 +135,25 @@ check_gateway_up_dependency() {
warning "SSH_PORT not set, using default: 2223"
fi
- # TUI (/tui on GatewayServer) bind host defaults to master node IP.
+ # INGRESS_VIP 用于 registry endpoint / ssh listen_host 等(见 gateway-config 模板)。
+ # 缺失时回退 MASTER_NODE_IP,避免渲染出 http://:4003 / 空 listen_host 等非法配置,
+ # 与下方 GATEWAY_HOST / WEB_HOST 的回退逻辑保持一致。
+ local ingress_vip
+ ingress_vip=$(_ingress_vip || true)
+ if [ -z "${ingress_vip}" ]; then
+ ingress_vip="${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ info "INGRESS_VIP not set, using MASTER_NODE_IP: ${ingress_vip}"
+ fi
+ DEPLOY_VARS["INGRESS_VIP"]="${ingress_vip}"
+ # TUI (/tui on GatewayServer) bind host defaults to ingress VIP (fallback MASTER_NODE_IP).
if [ -z "${DEPLOY_VARS["GATEWAY_HOST"]:-}" ]; then
- DEPLOY_VARS["GATEWAY_HOST"]="${DEPLOY_VARS["MASTER_NODE_IP"]}"
- info "GATEWAY_HOST not set, using MASTER_NODE_IP: ${DEPLOY_VARS["GATEWAY_HOST"]}"
+ if [ -n "${ingress_vip}" ]; then
+ DEPLOY_VARS["GATEWAY_HOST"]="${ingress_vip}"
+ info "GATEWAY_HOST defaulted to ingress_virtual_ip: ${ingress_vip}"
+ else
+ DEPLOY_VARS["GATEWAY_HOST"]="${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ info "GATEWAY_HOST not set, using MASTER_NODE_IP: ${DEPLOY_VARS["GATEWAY_HOST"]}"
+ fi
fi
if [ -z "${DEPLOY_VARS["GATEWAY_PORT"]:-}" ]; then
@@ -124,10 +161,15 @@ check_gateway_up_dependency() {
warning "GATEWAY_PORT not set, using default: 19001"
fi
- # WebChannel (/ws) bind host defaults to master node IP.
+ # WebChannel (/ws) bind host defaults to ingress VIP (fallback MASTER_NODE_IP).
if [ -z "${DEPLOY_VARS["WEB_HOST"]:-}" ]; then
- DEPLOY_VARS["WEB_HOST"]="${DEPLOY_VARS["MASTER_NODE_IP"]}"
- info "WEB_HOST not set, using MASTER_NODE_IP: ${DEPLOY_VARS["WEB_HOST"]}"
+ if [ -n "${ingress_vip}" ]; then
+ DEPLOY_VARS["WEB_HOST"]="${ingress_vip}"
+ info "WEB_HOST defaulted to ingress_virtual_ip: ${ingress_vip}"
+ else
+ DEPLOY_VARS["WEB_HOST"]="${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ info "WEB_HOST not set, using MASTER_NODE_IP: ${DEPLOY_VARS["WEB_HOST"]}"
+ fi
fi
if [ -z "${DEPLOY_VARS["WEB_PORT"]:-}" ]; then
diff --git a/deploy/yuanrong/conf/gateway-config-yuanrong.template.yaml b/deploy/yuanrong/conf/gateway-config-yuanrong.template.yaml
index 8af41c382e..f25c20feed 100644
--- a/deploy/yuanrong/conf/gateway-config-yuanrong.template.yaml
+++ b/deploy/yuanrong/conf/gateway-config-yuanrong.template.yaml
@@ -486,8 +486,8 @@ gateway:
# 空闲扫描周期(秒)
sandbox_idle_check_interval_seconds: 30
registry:
- # Agent OS 注册中心:host 来自 --hosts / CLUSTER_HOSTS 的 master IP
- endpoint: http://<<MASTER_NODE_IP>>:<<REGISTRY_PORT>>
+ # Agent OS 注册中心:endpoint 绑定 ingress_virtual_ip(VIP)(与本机注册中心绑定一致)
+ endpoint: http://<<INGRESS_VIP>>:<<REGISTRY_PORT>>
request_timeout_s: 10
# 本机 nodeIP,供 POST /api/nodes/{node}/heartbeat
node: <<MASTER_NODE_IP>>
@@ -674,8 +674,8 @@ channels:
# 客户端: ssh -p <listen_port> user@<gateway-host>
# 南向连接参数见 gateway.agentos.ssh;agent_type 跟随用户当前值(3rdagent.switch)。
enabled: true
- # 监听 IP:host 来自 --hosts / CLUSTER_HOSTS 的 master IP
- listen_host: <<MASTER_NODE_IP>>
+ # 监听 IP:绑定 ingress_virtual_ip(VIP),使 SSH 通道可通过统一入口访问
+ listen_host: <<INGRESS_VIP>>
listen_port: <<SSH_PORT>>
host_key_path: ~/.jiuwenswarm/config/ssh_host_key
relay_timeout_sec: 3600
diff --git a/deploy/yuanrong/gateway_handler.sh b/deploy/yuanrong/gateway_handler.sh
index 3314e1c79b..5651ebe945 100755
--- a/deploy/yuanrong/gateway_handler.sh
+++ b/deploy/yuanrong/gateway_handler.sh
@@ -38,20 +38,6 @@ gateway_check_jiuwenswarm_home() {
return 0
}
-gateway_resolve_host() {
- local master_host="${DEPLOY_VARS["MASTER_NODE_IP"]:-}"
- if [ -z "${master_host}" ]; then
- if [ -n "${DEPLOY_VARS["CLUSTER_HOSTS"]:-}" ]; then
- IFS=',' read -ra _gw_host_list <<< "${DEPLOY_VARS["CLUSTER_HOSTS"]}"
- master_host="${_gw_host_list[0]}"
- else
- master_host=$(get_local_ip)
- info "MASTER_NODE_IP not set, defaulting to local: ${master_host}" >&2
- fi
- fi
- echo "${master_host}"
-}
-
gateway_compute_extension_dirs() {
if [ -n "${DEPLOY_VARS["EXTENSION_DIRS"]:-}" ]; then
info "EXTENSION_DIRS already set: ${DEPLOY_VARS["EXTENSION_DIRS"]}"
@@ -59,7 +45,7 @@ gateway_compute_extension_dirs() {
fi
local master_host
- master_host=$(gateway_resolve_host)
+ master_host=$(get_local_ip) # gateway 在本机(ingress master)运行,EXTENSION_DIRS 取本机 jiuwenswarm 安装位置
local python_version="${DEPLOY_VARS["YR_PYTHON_VERSION"]}"
local jiuwenswarm_location
@@ -89,8 +75,15 @@ gateway_gen_config() {
}
gateway_deploy_process() {
+ # gateway 跟随 ingress_virtual_ip:仅在本机持有 VIP 时部署/启动 gateway,否则跳过。
+ # 不依赖 master_nodes / CLUSTER_HOSTS[0](可能有多个 master_nodes,且其 IP 与 VIP 不同)。
+ if ! /usr/local/bin/agentos-check-ingress-master >/dev/null 2>&1; then
+ warning "Local host does not hold ingress vip, skip gateway deploy process."
+ return 0
+ fi
+
local master_host
- master_host=$(gateway_resolve_host)
+ master_host=$(get_local_ip) # 本机即 ingress master,gateway 部署在本机
local instance_name="${DEPLOY_VARS["JIUWENSWARM_INSTANCE_NAME"]}"
info "Deploying gateway in process mode on ${master_host}..."
@@ -144,8 +137,14 @@ gateway_deploy_process() {
}
gateway_undeploy_process() {
+ # 与 up 对称:gateway 跟随 ingress_virtual_ip,仅在本机持有 VIP 时停止本机 gateway。
+ if ! /usr/local/bin/agentos-check-ingress-master >/dev/null 2>&1; then
+ warning "Local host does not hold ingress vip, skip stopping jiuwenswarm-gateway."
+ return 0
+ fi
+
local master_host
- master_host=$(gateway_resolve_host)
+ master_host=$(get_local_ip)
local instance_name="${DEPLOY_VARS["JIUWENSWARM_INSTANCE_NAME"]}"
info "Stopping gateway on ${master_host}..."
diff --git a/deploy/yuanrong/global_vars.sh b/deploy/yuanrong/global_vars.sh
index 04f448beef..9fe44cac76 100755
--- a/deploy/yuanrong/global_vars.sh
+++ b/deploy/yuanrong/global_vars.sh
@@ -47,6 +47,7 @@ declare -A DEPLOY_VARS=(
["FRONTEND_PORT"]=""
["FUNCTION_ID"]=""
["MASTER_NODE_IP"]=""
+ ["INGRESS_VIP"]=""
["REGISTRY_PORT"]=""
["SSH_PORT"]=""
# TUI GatewayServer bind host; empty → default to MASTER_NODE_IP at deploy check time