#!/bin/bash # DMS合规性测试工具 - 多服务启动脚本 # 这是supervisor的备选方案 set -e # 颜色定义 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color print_message() { echo -e "${GREEN}[INFO]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # 信号处理函数 cleanup() { print_message "正在停止服务..." if [ ! -z "$API_PID" ]; then kill $API_PID 2>/dev/null || true wait $API_PID 2>/dev/null || true print_message "API服务已停止" fi if [ ! -z "$HISTORY_PID" ]; then kill $HISTORY_PID 2>/dev/null || true wait $HISTORY_PID 2>/dev/null || true print_message "历史查看器服务已停止" fi exit 0 } # 捕获退出信号 trap cleanup SIGTERM SIGINT print_message "启动DMS合规性测试工具服务..." # 创建日志目录 mkdir -p /app/logs # 启动API服务器 print_message "启动API服务器 (端口5050)..." python /app/api_server.py > /app/logs/api_server.log 2>&1 & API_PID=$! # 启动历史查看器 print_message "启动历史查看器 (端口5051)..." python /app/history_viewer.py > /app/logs/history_viewer.log 2>&1 & HISTORY_PID=$! print_message "服务启动完成" print_message "API服务PID: $API_PID" print_message "历史查看器PID: $HISTORY_PID" print_message "API服务地址: http://localhost:5050" print_message "历史查看器地址: http://localhost:5051" # 等待服务启动 sleep 5 # 检查服务状态 if kill -0 $API_PID 2>/dev/null; then print_message "✅ API服务运行正常" else print_error "❌ API服务启动失败" cat /app/logs/api_server.log exit 1 fi if kill -0 $HISTORY_PID 2>/dev/null; then print_message "✅ 历史查看器服务运行正常" else print_error "❌ 历史查看器服务启动失败" cat /app/logs/history_viewer.log exit 1 fi print_message "所有服务运行正常,等待信号..." # 持续监控服务状态 while true; do # 检查API服务 if ! kill -0 $API_PID 2>/dev/null; then print_error "API服务异常退出,重新启动..." python /app/api_server.py > /app/logs/api_server.log 2>&1 & API_PID=$! fi # 检查历史查看器服务 if ! kill -0 $HISTORY_PID 2>/dev/null; then print_error "历史查看器服务异常退出,重新启动..." python /app/history_viewer.py > /app/logs/history_viewer.log 2>&1 & HISTORY_PID=$! fi sleep 10 done