Files
gangyan/langchain-chat/start.sh

61 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 启动 Python 后端服务脚本(使用 nohup
# 颜色定义
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# 检查是否已有进程在运行
EXISTING=$(ps aux | grep "[p]ython.*startup.py -a" | awk '{print $2}')
if [ -n "$EXISTING" ]; then
echo -e "${YELLOW}警告: 检测到已有 Python 后端进程在运行 (PID: $EXISTING)${NC}"
read -p "是否先停止现有进程? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}正在停止现有进程...${NC}"
kill $EXISTING 2>/dev/null
sleep 2
# 如果还在运行,强制终止
if ps -p $EXISTING > /dev/null 2>&1; then
kill -9 $EXISTING 2>/dev/null
fi
echo -e "${GREEN}已停止现有进程${NC}"
else
echo -e "${RED}请先停止现有进程或使用 stop.sh${NC}"
exit 1
fi
fi
# 获取脚本所在目录
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# 设置 PDF 转换服务环境变量(确保与 pdf-convert-service 一致)
export PDF_CONVERT_KB_ROOT="${PDF_CONVERT_KB_ROOT:-$SCRIPT_DIR/knowledge_base}"
# 检查 conda 环境
if ! command -v conda &> /dev/null; then
echo -e "${RED}错误: 未找到 conda 命令${NC}"
exit 1
fi
# 激活 conda 环境并启动
echo -e "${YELLOW}正在启动 Python 后端...${NC}"
echo -e "${YELLOW}使用环境: gangyan${NC}"
echo -e "${YELLOW}日志文件: nohup.out${NC}"
# 使用 nohup 启动
nohup conda run -n gangyan python startup.py -a > nohup.out 2>&1 &
PID=$!
echo -e "${GREEN}后端已启动PID: $PID${NC}"
echo -e "${YELLOW}查看日志: tail -f nohup.out${NC}"
echo -e "${YELLOW}停止服务: ./stop.sh${NC}"
# 等待几秒后显示日志
sleep 2
echo -e "\n${YELLOW}=== 最近日志 ===${NC}"
tail -20 nohup.out