From 7b011da2645b1665e730ccf56c929d870a1e3cc4 Mon Sep 17 00:00:00 2001 From: potaser Date: Wed, 5 Aug 2026 20:15:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=20main.py=20=E6=8C=87=E5=90=91=E4=BA=86?= =?UTF-8?q?=E6=96=B0extension=5Fstage=5Flightweight.api=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=202.=20=E4=BC=98=E5=8C=96=E4=BA=86start=5F*=5F9000.sh=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E4=BC=98=E5=85=88=E6=A0=B9=E6=8D=AEenv?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=90=AF=E5=8A=A8=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=203.=20=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80=E9=94=AE=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E8=84=9A=E6=9C=ACmanage=5Fplantai.sh=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=94=B1Agent=E9=80=9A=E8=BF=87promot?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=AF=B4=E5=90=AF=E5=8A=A8=E3=80=81=E9=87=8D?= =?UTF-8?q?=E5=90=AF=E7=AD=89=E8=BF=9B=E8=A1=8C=E6=9C=8D=E5=8A=A1=E7=9A=84?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=92=8C=E5=85=B3=E9=97=AD=E5=8F=8A=E9=87=8D?= =?UTF-8?q?=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/vue3/main.py | 3 + manage_plantai.sh | 161 ++++++++++++++++++++++++++++++++++++++++++ start_celery_9000.sh | 6 +- start_plantai_9000.sh | 9 ++- 4 files changed, 174 insertions(+), 5 deletions(-) create mode 100755 manage_plantai.sh diff --git a/apps/web/vue3/main.py b/apps/web/vue3/main.py index d8499c7c5..22962c7f0 100644 --- a/apps/web/vue3/main.py +++ b/apps/web/vue3/main.py @@ -4191,6 +4191,9 @@ def _attach_agent_manifest_status(task: Dict) -> None: print(f"[API DEBUG] Failed to attach agent manifest status: {e}") app = FastAPI(title="BotanicalBaseAgent API") +from gfa_core.extension_stage_lightweight.api import create_lightweight_extension_router + +app.include_router(create_lightweight_extension_router()) # MainAgent runtime state. Analysis planning and execution remain owned by # the original IntentAgent/PlanningAgent/frontend flow below. llm_manager = None diff --git a/manage_plantai.sh b/manage_plantai.sh new file mode 100755 index 000000000..cbb9b7e19 --- /dev/null +++ b/manage_plantai.sh @@ -0,0 +1,161 @@ +#!/bin/bash +# PlantAI-dev 9000 服务管理脚本 +# 用法: bash manage_plantai.sh {start|stop|restart|status} +# +# 项目: /home/xzq/5090/teamWorkspace/zh/PlantAI-dev +# 端口: 9000 (web), Redis DB 14 (queue prefix: plantai_dev_9002) + +set -euo pipefail + +# Conda 环境:启动脚本内部也依赖这个环境 +CONDA_ENV="${CONDA_ENV:-/home/xzq/miniconda3/envs/test4py311}" +export PATH="$CONDA_ENV/bin:$PATH" + +# 项目配置(与 .env 和启动脚本保持一致) +PROJECT_DIR="/home/xzq/5090/teamWorkspace/zh/PlantAI-dev" +WEB_PORT="9000" +QUEUE_PREFIX="plantai_dev_9002" +WEB_LOG="/tmp/plantai_9000.log" +CELERY_LOG="/tmp/celery_9000.log" + +red() { echo -e "\033[31m$*\033[0m"; } +green(){ echo -e "\033[32m$*\033[0m"; } +cyan() { echo -e "\033[36m$*\033[0m"; } + +status() { + echo "" + cyan "=== PlantAI-dev 9000 服务状态 ===" + echo "" + + # Web 服务 + WEB_PID=$(ss -tlnp 2>/dev/null | grep ":$WEB_PORT " | grep -oP 'pid=\K\d+' || true) + if [ -n "${WEB_PID:-}" ]; then + green "[✓] Web 服务运行中 (端口 $WEB_PORT, PID $WEB_PID)" + else + red "[✗] Web 服务未启动 (端口 $WEB_PORT)" + fi + + # Redis + if redis-cli ping > /dev/null 2>&1; then + green "[✓] Redis 运行中 (localhost:6379)" + else + red "[✗] Redis 未启动" + fi + + # Celery workers + CELERY_COUNT=$(pgrep -fc "$QUEUE_PREFIX" || echo 0) + if [ "$CELERY_COUNT" -gt 0 ]; then + green "[✓] Celery workers 运行中 (${CELERY_COUNT} 进程, 队列前缀: $QUEUE_PREFIX)" + echo " Worker 列表:" + ps aux | grep "$QUEUE_PREFIX" | grep -v grep | grep -oP "queues=\K\S+" | sort | while read q; do + echo " - $q" + done + else + red "[✗] Celery workers 未启动 (队列前缀: $QUEUE_PREFIX)" + fi + echo "" +} + +stop() { + echo "" + cyan "=== 停止 PlantAI-dev 9000 服务 ===" + echo "" + + # 停止 Web 服务 + WEB_PID=$(ss -tlnp 2>/dev/null | grep ":$WEB_PORT " | grep -oP 'pid=\K\d+' || true) + if [ -n "${WEB_PID:-}" ]; then + echo "正在停止 Web 服务 (PID $WEB_PID)..." + kill "$WEB_PID" 2>/dev/null || true + sleep 1 + # 如果还没死,强制 kill + if ss -tlnp 2>/dev/null | grep -q ":$WEB_PORT"; then + kill -9 "$WEB_PID" 2>/dev/null || true + fi + green "[✓] Web 服务已停止" + else + echo "[ ] Web 服务未运行" + fi + + # 停止 Celery workers + CELERY_PIDS=$(pgrep -f "$QUEUE_PREFIX" 2>/dev/null) || true + if [ -n "${CELERY_PIDS:-}" ]; then + echo "正在停止 Celery workers..." + echo "$CELERY_PIDS" | xargs -r kill 2>/dev/null || true + sleep 2 + # 清理残留 + REMAIN=$(pgrep -f "$QUEUE_PREFIX" 2>/dev/null) || true + if [ -n "${REMAIN:-}" ]; then + echo " 强制清理残留进程..." + echo "$REMAIN" | xargs -r kill -9 2>/dev/null || true + fi + green "[✓] Celery workers 已停止" + else + echo "[ ] Celery workers 未运行" + fi + echo "" +} + +start() { + echo "" + cyan "=== 启动 PlantAI-dev 9000 服务 ===" + echo "" + + # 检查是否已在运行 + if ss -tlnp 2>/dev/null | grep -q ":$WEB_PORT"; then + red "[!] 端口 $WEB_PORT 已被占用,请先停止服务" + exit 1 + fi + + if ! redis-cli ping > /dev/null 2>&1; then + red "[!] Redis 未运行,请先启动 Redis" + exit 1 + fi + + cd "$PROJECT_DIR" + + # 启动 Celery workers + echo "正在启动 Celery workers..." + nohup bash start_celery_9000.sh > "$CELERY_LOG" 2>&1 & + sleep 3 + CELERY_COUNT=$(pgrep -fc "$QUEUE_PREFIX" || echo 0) + if [ "$CELERY_COUNT" -gt 0 ]; then + green " [✓] Celery workers 已启动 (${CELERY_COUNT} 进程)" + else + red " [✗] Celery workers 启动失败,查看 $CELERY_LOG" + fi + + # 启动 Web 服务 + echo "正在启动 Web 服务..." + nohup bash start_plantai_9000.sh > "$WEB_LOG" 2>&1 & + sleep 3 + if ss -tlnp 2>/dev/null | grep -q ":$WEB_PORT"; then + green " [✓] Web 服务已启动 (http://0.0.0.0:$WEB_PORT)" + else + red " [✗] Web 服务启动失败,查看 $WEB_LOG" + fi + + # 最终状态 + echo "" + echo "日志文件:" + echo " Web: $WEB_LOG" + echo " Celery: $CELERY_LOG" + echo " Worker: $PROJECT_DIR/logs/celery_plantai_dev_9000/" + echo "" +} + +restart() { + stop + sleep 1 + start +} + +case "${1:-status}" in + start) start ;; + stop) stop ;; + restart) restart ;; + status) status ;; + *) + echo "用法: bash manage_plantai.sh {start|stop|restart|status}" + exit 1 + ;; +esac diff --git a/start_celery_9000.sh b/start_celery_9000.sh index 50a257db2..2496254f8 100755 --- a/start_celery_9000.sh +++ b/start_celery_9000.sh @@ -25,13 +25,13 @@ fi if [ -n "$EXTERNAL_BBAV5_WORKER_NAME_PREFIX" ]; then BBAV5_WORKER_NAME_PREFIX="$EXTERNAL_BBAV5_WORKER_NAME_PREFIX" fi -if [ -z "$EXTERNAL_BBAV5_QUEUE_PREFIX" ]; then +if [ -z "${BBAV5_QUEUE_PREFIX-}" ]; then BBAV5_QUEUE_PREFIX="plantai_dev_9000" fi -if [ -z "$EXTERNAL_BBAV5_REDIS_URL" ]; then +if [ -z "${BBAV5_REDIS_URL-}" ]; then BBAV5_REDIS_URL="redis://localhost:6379/10" fi -if [ -z "$EXTERNAL_BBAV5_CELERY_LOG_DIR" ]; then +if [ -z "${BBAV5_CELERY_LOG_DIR-}" ]; then BBAV5_CELERY_LOG_DIR="logs/celery_plantai_dev_9000" fi if [ -z "$EXTERNAL_BBAV5_WORKER_NAME_PREFIX" ]; then diff --git a/start_plantai_9000.sh b/start_plantai_9000.sh index e907169fa..ab815fdb5 100755 --- a/start_plantai_9000.sh +++ b/start_plantai_9000.sh @@ -15,12 +15,17 @@ export PATH="$CONDA_ENV/bin:$PATH" # the caller's shell; GWAS/other sandboxes have dedicated restart scripts. export BBAV5_PROJECT_ROOT="$SCRIPT_DIR" export PLANTAI_PROJECT_ROOT="$SCRIPT_DIR" +if [ -f "$SCRIPT_DIR/.env" ]; then + set -a + . "$SCRIPT_DIR/.env" + set +a +fi export BBAV5_PROJECT_ENV_FILE="${BBAV5_PROJECT_ENV_FILE:-$SCRIPT_DIR/.env}" export BBAV5_LIGHTWEIGHT_EXTENSION_STORE="${BBAV5_LIGHTWEIGHT_EXTENSION_STORE:-$SCRIPT_DIR/.runtime/lightweight-extension/store}" export BBAV5_LIGHTWEIGHT_INPUT="${BBAV5_LIGHTWEIGHT_INPUT:-$SCRIPT_DIR/input}" export BBAV5_LIGHTWEIGHT_WORKSPACE="${BBAV5_LIGHTWEIGHT_WORKSPACE:-$SCRIPT_DIR/workspace}" -export BBAV5_QUEUE_PREFIX="plantai_dev_9000" -export BBAV5_REDIS_URL="redis://localhost:6379/10" +export BBAV5_QUEUE_PREFIX="${BBAV5_QUEUE_PREFIX:-plantai_dev_9000}" +export BBAV5_REDIS_URL="${BBAV5_REDIS_URL:-redis://localhost:6379/10}" export PLANTAI_WEB_PORT="9000" export GENE_FAMILY_MAS_API="http://127.0.0.1:7926" export DUAL_KB_QA_BASE_URL="http://127.0.0.1:7926" From 4750bcc76f48ccf5b6cd8ed91f0482b752524593 Mon Sep 17 00:00:00 2001 From: potaser Date: Thu, 6 Aug 2026 19:34:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E5=8F=AF=E4=BB=A5=E6=8C=87=E5=AE=9Aweb?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=9B=E5=B0=86?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E8=BF=90=E8=A1=8C=E7=BB=93=E6=9E=9C=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E6=8C=AA=E5=88=B0=E4=BA=86=E6=8B=93=E5=B1=95=E5=88=86?= =?UTF-8?q?=E6=9E=90title=E7=9A=84=E5=90=8E=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/vue3/index.html | 2 +- manage_plantai.sh | 46 ++++++++++++++++++++++++++++++---------- restart_plantai_9000.sh | 24 +++++++++++++++++++++ start_plantai_9000.sh | 23 ++++++++++++++++++-- 4 files changed, 81 insertions(+), 14 deletions(-) create mode 100755 restart_plantai_9000.sh diff --git a/apps/web/vue3/index.html b/apps/web/vue3/index.html index c1acbfe65..5281b307c 100644 --- a/apps/web/vue3/index.html +++ b/apps/web/vue3/index.html @@ -1365,6 +1365,7 @@

拓展分析阶段

+ 运行结果
已写阶段 @@ -1425,7 +1426,6 @@ 运行已发布 - 运行结果
diff --git a/manage_plantai.sh b/manage_plantai.sh index cbb9b7e19..52b893ae5 100755 --- a/manage_plantai.sh +++ b/manage_plantai.sh @@ -1,22 +1,46 @@ #!/bin/bash # PlantAI-dev 9000 服务管理脚本 -# 用法: bash manage_plantai.sh {start|stop|restart|status} +# 用法: bash manage_plantai.sh {start|stop|restart|status} [--port PORT] +# 默认端口: 9000 # # 项目: /home/xzq/5090/teamWorkspace/zh/PlantAI-dev # 端口: 9000 (web), Redis DB 14 (queue prefix: plantai_dev_9002) set -euo pipefail +# 解析命令行参数:第一个参数是命令,后面可选 --port / -p +CMD="" +WEB_PORT="9000" +for arg in "$@"; do + case "$arg" in + start|stop|restart|status) + CMD="$arg" + ;; + --port|-p) + WEB_PORT="" + ;; + *) + if [ -z "$WEB_PORT" ] && [[ "$arg" =~ ^[0-9]+$ ]]; then + WEB_PORT="$arg" + elif [ -z "$CMD" ]; then + echo "错误: 未知命令 '$arg'" + echo "用法: bash manage_plantai.sh {start|stop|restart|status} [--port PORT]" + exit 1 + fi + ;; + esac +done +CMD="${CMD:-status}" + # Conda 环境:启动脚本内部也依赖这个环境 CONDA_ENV="${CONDA_ENV:-/home/xzq/miniconda3/envs/test4py311}" export PATH="$CONDA_ENV/bin:$PATH" # 项目配置(与 .env 和启动脚本保持一致) PROJECT_DIR="/home/xzq/5090/teamWorkspace/zh/PlantAI-dev" -WEB_PORT="9000" QUEUE_PREFIX="plantai_dev_9002" -WEB_LOG="/tmp/plantai_9000.log" -CELERY_LOG="/tmp/celery_9000.log" +WEB_LOG="/tmp/plantai_${WEB_PORT}.log" +CELERY_LOG="/tmp/celery_${WEB_PORT}.log" red() { echo -e "\033[31m$*\033[0m"; } green(){ echo -e "\033[32m$*\033[0m"; } @@ -24,7 +48,7 @@ cyan() { echo -e "\033[36m$*\033[0m"; } status() { echo "" - cyan "=== PlantAI-dev 9000 服务状态 ===" + cyan "=== PlantAI-dev ${WEB_PORT} 服务状态 ===" echo "" # Web 服务 @@ -58,7 +82,7 @@ status() { stop() { echo "" - cyan "=== 停止 PlantAI-dev 9000 服务 ===" + cyan "=== 停止 PlantAI-dev ${WEB_PORT} 服务 ===" echo "" # 停止 Web 服务 @@ -97,7 +121,7 @@ stop() { start() { echo "" - cyan "=== 启动 PlantAI-dev 9000 服务 ===" + cyan "=== 启动 PlantAI-dev ${WEB_PORT} 服务 ===" echo "" # 检查是否已在运行 @@ -126,7 +150,7 @@ start() { # 启动 Web 服务 echo "正在启动 Web 服务..." - nohup bash start_plantai_9000.sh > "$WEB_LOG" 2>&1 & + nohup bash start_plantai_9000.sh --port "$WEB_PORT" > "$WEB_LOG" 2>&1 & sleep 3 if ss -tlnp 2>/dev/null | grep -q ":$WEB_PORT"; then green " [✓] Web 服务已启动 (http://0.0.0.0:$WEB_PORT)" @@ -139,7 +163,7 @@ start() { echo "日志文件:" echo " Web: $WEB_LOG" echo " Celery: $CELERY_LOG" - echo " Worker: $PROJECT_DIR/logs/celery_plantai_dev_9000/" + echo " Worker: $PROJECT_DIR/logs/celery_${QUEUE_PREFIX}/" echo "" } @@ -149,13 +173,13 @@ restart() { start } -case "${1:-status}" in +case "$CMD" in start) start ;; stop) stop ;; restart) restart ;; status) status ;; *) - echo "用法: bash manage_plantai.sh {start|stop|restart|status}" + echo "用法: bash manage_plantai.sh {start|stop|restart|status} [--port PORT]" exit 1 ;; esac diff --git a/restart_plantai_9000.sh b/restart_plantai_9000.sh new file mode 100755 index 000000000..06e7bab13 --- /dev/null +++ b/restart_plantai_9000.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Project restart script — called by /api/admin/restart-project +# 用法: bash restart_plantai_9000.sh [--port PORT] +# 从环境变量 PLANTAI_WEB_PORT 或参数获取端口,默认 9000 + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +PORT="${PLANTAI_WEB_PORT:-9000}" +while [[ $# -gt 0 ]]; do + case "$1" in + --port|-p) + PORT="${2:?错误: --port 需要指定端口号}" + shift 2 + ;; + *) + shift + ;; + esac +done + +cd "$SCRIPT_DIR" +exec bash manage_plantai.sh restart --port "$PORT" diff --git a/start_plantai_9000.sh b/start_plantai_9000.sh index ab815fdb5..93050a096 100755 --- a/start_plantai_9000.sh +++ b/start_plantai_9000.sh @@ -1,8 +1,26 @@ #!/bin/bash -# Start the PlantAI-dev web service on port 9000. +# Start the PlantAI-dev web service. +# 用法: bash start_plantai_9000.sh [--port PORT] +# 默认端口: 9000 set -euo pipefail +# 解析命令行参数 +PORT="9000" +while [[ $# -gt 0 ]]; do + case "$1" in + --port|-p) + PORT="${2:?错误: --port 需要指定端口号}" + shift 2 + ;; + *) + echo "未知参数: $1" + echo "用法: bash start_plantai_9000.sh [--port PORT]" + exit 1 + ;; + esac +done + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" @@ -26,7 +44,8 @@ export BBAV5_LIGHTWEIGHT_INPUT="${BBAV5_LIGHTWEIGHT_INPUT:-$SCRIPT_DIR/input}" export BBAV5_LIGHTWEIGHT_WORKSPACE="${BBAV5_LIGHTWEIGHT_WORKSPACE:-$SCRIPT_DIR/workspace}" export BBAV5_QUEUE_PREFIX="${BBAV5_QUEUE_PREFIX:-plantai_dev_9000}" export BBAV5_REDIS_URL="${BBAV5_REDIS_URL:-redis://localhost:6379/10}" -export PLANTAI_WEB_PORT="9000" +export PLANTAI_WEB_PORT="$PORT" +export PLANTAI_RESTART_SCRIPT="$SCRIPT_DIR/restart_plantai_9000.sh" export GENE_FAMILY_MAS_API="http://127.0.0.1:7926" export DUAL_KB_QA_BASE_URL="http://127.0.0.1:7926" export RAG_API_URL="http://127.0.0.1:7926/api/v1/qa-v1-1-73/chat"