#!/bin/bash # 颜色定义 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}考培练系统后端启动脚本${NC}" echo "================================" # 检查Python版本 echo -e "${YELLOW}检查Python版本...${NC}" python_version=$(python3 --version 2>&1) if [[ $? -eq 0 ]]; then echo -e "${GREEN}✓ $python_version${NC}" else echo -e "${RED}✗ Python3未安装${NC}" exit 1 fi # 检查虚拟环境 if [ ! -d "venv" ]; then echo -e "${YELLOW}创建虚拟环境...${NC}" python3 -m venv venv fi # 激活虚拟环境 echo -e "${YELLOW}激活虚拟环境...${NC}" source venv/bin/activate # 安装依赖 echo -e "${YELLOW}安装依赖...${NC}" pip install -q -r requirements/base.txt # 检查.env文件 if [ ! -f ".env" ]; then echo -e "${YELLOW}创建.env文件...${NC}" cp .env.example .env echo -e "${GREEN}✓ 已创建.env文件,请根据需要修改配置${NC}" fi # 检查数据库连接 echo -e "${YELLOW}检查数据库连接...${NC}" python -c " import os from dotenv import load_dotenv load_dotenv() db_url = os.getenv('DATABASE_URL', '') if 'mysql' in db_url: print('✓ 数据库配置已设置') else: print('⚠ 请检查数据库配置') " 2>/dev/null # 启动服务 echo -e "${GREEN}启动开发服务器...${NC}" echo "================================" echo -e "API文档: ${GREEN}http://localhost:8000/api/docs${NC}" echo -e "健康检查: ${GREEN}http://localhost:8000/health${NC}" echo "================================" # 启动uvicorn uvicorn app.main:app --reload --host 0.0.0.0 --port 8000