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

fix(deploy): gateway部署默认在本机节点执行

tianmengyue515e32e204fb
diff --git a/deploy/yuanrong/.env.example b/deploy/yuanrong/.env.example
index 5d5f46f7fb..b3975d7660 100644
--- a/deploy/yuanrong/.env.example
+++ b/deploy/yuanrong/.env.example
@@ -38,6 +38,9 @@ MGR_MAX_INSTANCE=10
# 服务并发处理数量/最大并发数
MGR_CONCURRENT_NUM=10
+# 沙箱类型(留空为默认沙箱;可配置为 "supervisor" 使用 supervisor 沙箱)
+SANDBOX_TYPE=""
+
# ====================== Gateway配置 ======================
# jiuwenswarm 实例名(留空则使用默认路径 ~/.jiuwenswarm)
# 如果指定了实例名,配置目录变为 ~/.jiuwenswarm-instances/<实例名>
diff --git a/deploy/yuanrong/check_handler.sh b/deploy/yuanrong/check_handler.sh
index a4b82997ca..43e2e0ab04 100755
--- a/deploy/yuanrong/check_handler.sh
+++ b/deploy/yuanrong/check_handler.sh
@@ -91,7 +91,10 @@ check_gateway_up_dependency() {
DEPLOY_VARS["MASTER_NODE_IP"]="${_gw_host_list[0]}"
info "MASTER_NODE_IP inferred from CLUSTER_HOSTS: ${DEPLOY_VARS["MASTER_NODE_IP"]}"
else
- error "MASTER_NODE_IP is not set. Please set it in .env.custom or deploy jiuwenswarm first."
+ local local_ip
+ local_ip=$(get_local_ip)
+ DEPLOY_VARS["MASTER_NODE_IP"]="${local_ip}"
+ info "MASTER_NODE_IP not set, defaulting to local: ${local_ip}"
fi
fi
diff --git a/deploy/yuanrong/conf/claw_meta_process.template.json b/deploy/yuanrong/conf/claw_meta_process.template.json
index d1a468a44e..0c97a4e098 100644
--- a/deploy/yuanrong/conf/claw_meta_process.template.json
+++ b/deploy/yuanrong/conf/claw_meta_process.template.json
@@ -31,5 +31,6 @@
"storageType": "local",
"codePath": "<<YR_FUNC_CODE_DIR>>",
"s3CodePath": {},
- "enableSessionCtx": true
+ "enableSessionCtx": true,
+ "sandboxType": "<<SANDBOX_TYPE>>"
}
diff --git a/deploy/yuanrong/gateway_handler.sh b/deploy/yuanrong/gateway_handler.sh
index 1f0ce28c6e..f1a18e714a 100755
--- a/deploy/yuanrong/gateway_handler.sh
+++ b/deploy/yuanrong/gateway_handler.sh
@@ -10,13 +10,28 @@ gateway_get_config_dir() {
fi
}
+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"]}"
return 0
fi
- local master_host="${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ local master_host
+ master_host=$(gateway_resolve_host)
local python_version="${DEPLOY_VARS["YR_PYTHON_VERSION"]}"
local jiuwenswarm_location
@@ -46,7 +61,8 @@ gateway_gen_config() {
}
gateway_deploy_process() {
- local master_host="${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ local master_host
+ master_host=$(gateway_resolve_host)
local instance_name="${DEPLOY_VARS["JIUWENSWARM_INSTANCE_NAME"]}"
info "Deploying gateway in process mode on ${master_host}..."
@@ -95,24 +111,16 @@ gateway_deploy_process() {
}
gateway_undeploy_process() {
- local master_host="${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ local master_host
+ master_host=$(gateway_resolve_host)
local instance_name="${DEPLOY_VARS["JIUWENSWARM_INSTANCE_NAME"]}"
- 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
- error "MASTER_NODE_IP is not set. Cannot determine which host to stop gateway on."
- fi
- fi
-
info "Stopping gateway on ${master_host}..."
if [ -n "${instance_name}" ]; then
- exec_on_host "${master_host}" "pkill -f 'JIUWENSWARM_DATA_DIR=/root/.jiuwenswarm-instances/${instance_name}.*jiuwenswarm-gateway' || true"
+ exec_on_host "${master_host}" "pkill -f 'JIUWENSWARM_DATA_DIR=/root/.jiuwenswarm-instances/${instance_name}.*[j]iuwenswarm-gateway' || true"
else
- exec_on_host "${master_host}" "pkill -f 'jiuwenswarm-gateway' || true"
+ exec_on_host "${master_host}" "pkill -f '[j]iuwenswarm-gateway' || true"
fi
success "Gateway stopped on ${master_host}"
diff --git a/deploy/yuanrong/global_vars.sh b/deploy/yuanrong/global_vars.sh
index 0a819e50d5..c6529fc07a 100755
--- a/deploy/yuanrong/global_vars.sh
+++ b/deploy/yuanrong/global_vars.sh
@@ -22,6 +22,7 @@ declare -ga MODULES=()
declare -A DEPLOY_VARS=(
["FUNC_SVC_NAME"]="0@jiuwen@swarm"
+ ["SANDBOX_TYPE"]=""
["MGR_CPU"]="300"
["MGR_MEMORY"]="600"
["MGR_MIN_INSTANCE"]="1"
diff --git a/deploy/yuanrong/jiuwenswarm_handler.sh b/deploy/yuanrong/jiuwenswarm_handler.sh
index a4a3c48fb2..9ac410513d 100644
--- a/deploy/yuanrong/jiuwenswarm_handler.sh
+++ b/deploy/yuanrong/jiuwenswarm_handler.sh
@@ -255,10 +255,12 @@ deploy_jiuwenswarm() {
}
uninstall_jiuwenswarm() {
- local hosts_str="${DEPLOY_VARS["CLUSTER_HOSTS"]}"
+ local hosts_str="${DEPLOY_VARS["CLUSTER_HOSTS"]:-}"
if [ -z "${hosts_str}" ]; then
- error "CLUSTER_HOSTS is not set. Cannot determine master host."
+ hosts_str=$(get_local_ip)
+ DEPLOY_VARS["CLUSTER_HOSTS"]="${hosts_str}"
+ warning "CLUSTER_HOSTS not set, using local IP: ${hosts_str}"
fi
IFS=',' read -ra JIUWENSWARM_HOST_LIST <<< "${hosts_str}"
@@ -279,7 +281,7 @@ uninstall_jiuwenswarm() {
info "curl -H \"Content-type: application/json\" -X DELETE ${delete_url}"
local res
- res=$(curl -s -H "Content-type: application/json" -X DELETE "${delete_url}")
+ res=$(curl -s -H "Content-type: application/json" -X DELETE "${delete_url}" || true)
info "Function unregistration result: ${res}"
# DELETE 成功返回 {}(无 code 字段)或 code=0;其他视为失败