From 68e6bad3ca3a1a8092fcc98cce54ea07825e4baf Mon Sep 17 00:00:00 2001 From: MT-Fire <798521692@qq.com> Date: Wed, 4 Mar 2026 09:43:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- start.sh | 43 ++++++++++++++++++++++++++++++++++++++++++ start_python_server.sh | 27 -------------------------- stop_python_server.sh | 13 ------------- 3 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 start.sh delete mode 100644 start_python_server.sh delete mode 100644 stop_python_server.sh diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..109d3f7 --- /dev/null +++ b/start.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +echo "==========================================" +echo " 启动 AI Chat 平台 (前端 + 后端) " +echo "==========================================" + +# 设置清理函数,在收到 Ctrl+C 时关闭所有子进程 +cleanup() { + echo "" + echo "正在关闭所有服务..." + kill $(jobs -p) 2>/dev/null + exit +} + +# 捕获退出信号 +trap cleanup SIGINT SIGTERM EXIT + +# 启动后端 +echo "[系统] 正在启动后端服务器..." +cd /home/mt/project/ai-chat-ui/server +if [ -d ".venv" ]; then + source .venv/bin/activate + # 使用 -u 参数强制不缓冲输出,实时显示日志 + python3 -u main.py & +else + echo "[错误] 未找到虚拟环境 (.venv)。请先创建。" +fi + +# 等待一小段时间确保后端启动 +sleep 2 + +# 启动前端 +echo "[系统] 正在启动前端服务器..." +cd /home/mt/project/ai-chat-ui +# 启动 vite 开发服务器 +npm run dev & + +echo "==========================================" +echo " 服务已启动,按 Ctrl+C 停止 " +echo "==========================================" + +# 使用 wait 阻塞主进程,保持脚本运行,这样可以看到调试打印信息 +wait diff --git a/start_python_server.sh b/start_python_server.sh deleted file mode 100644 index 979d23c..0000000 --- a/start_python_server.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# 启动Python服务器的增强脚本 - -echo "启动Python AI Chat服务器..." - -# 检查是否有服务器已经在8000端口运行 -if lsof -Pi :8000 -sTCP:LISTEN -t >/dev/null; then - echo "错误: 端口8000已被占用。请先停止占用该端口的进程。" - exit 1 -fi - -# 切换到服务器目录 -cd /home/mt/project/ai-chat-ui/server - -# 检查虚拟环境是否存在 -if [ ! -d ".venv" ]; then - echo "错误: 虚拟环境不存在。请先创建虚拟环境:" - echo "python3 -m venv .venv" - echo "source .venv/bin/activate" - echo "pip install -r requirements.txt" - exit 1 -fi - -echo "虚拟环境已找到,正在激活..." - -# 激活虚拟环境并启动服务器 -source .venv/bin/activate && python3 main.py \ No newline at end of file diff --git a/stop_python_server.sh b/stop_python_server.sh deleted file mode 100644 index be33f9f..0000000 --- a/stop_python_server.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# 停止Python服务器的脚本 - -echo "正在停止Python AI Chat服务器..." - -# 查找并终止在8000端口运行的Python进程 -PID=$(lsof -t -i:8000) -if [ -n "$PID" ]; then - kill $PID - echo "服务器进程 (PID: $PID) 已停止" -else - echo "在端口8000上没有找到运行的服务器" -fi \ No newline at end of file