#!/bin/bash # 情绪博物馆微服务停止脚本 # 作者: emotion-museum # 日期: 2025-07-12 echo "==========================================" echo "情绪博物馆微服务停止脚本" echo "==========================================" # 停止服务函数 stop_service() { local service_name=$1 local pid_file="logs/${service_name}.pid" if [ -f "$pid_file" ]; then local pid=$(cat $pid_file) if ps -p $pid > /dev/null 2>&1; then echo "停止 $service_name 服务 (PID: $pid)..." kill $pid # 等待进程结束 local count=0 while [ $count -lt 10 ]; do if ! ps -p $pid > /dev/null 2>&1; then echo "$service_name 服务已停止" rm -f $pid_file return 0 fi sleep 1 count=$((count + 1)) done # 强制杀死进程 echo "强制停止 $service_name 服务..." kill -9 $pid 2>/dev/null rm -f $pid_file else echo "$service_name 服务未运行" rm -f $pid_file fi else echo "$service_name 服务PID文件不存在" fi } # 停止所有微服务 echo "开始停止微服务..." # 停止统计分析服务 stop_service "emotion-stats" # 停止成就奖励服务 stop_service "emotion-reward" # 停止地图探索服务 stop_service "emotion-explore" # 停止成长课题服务 stop_service "emotion-growth" # 停止情绪记录服务 stop_service "emotion-record" # 停止AI对话服务 stop_service "emotion-ai" # 停止WebSocket聊天服务 stop_service "emotion-websocket" # 停止用户服务 stop_service "emotion-user" # 停止网关服务 stop_service "emotion-gateway" # 清理可能残留的Java进程 echo "清理残留进程..." pkill -f "emotion-gateway" pkill -f "emotion-user" pkill -f "emotion-ai" pkill -f "emotion-websocket" pkill -f "emotion-record" pkill -f "emotion-growth" pkill -f "emotion-explore" pkill -f "emotion-reward" pkill -f "emotion-stats" echo "" echo "==========================================" echo "所有微服务已停止!" echo "=========================================="