agricultural-sock-amalysis/stop-system.sh

84 lines
2.5 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
# ===========================================
# 农业股票数据分析系统停止脚本
# ===========================================
echo "🛑 正在停止农业股票数据分析系统..."
echo "=========================================="
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 停止服务的函数
stop_service() {
local service_name=$1
local pid_file=$2
if [ -f "$pid_file" ]; then
local pid=$(cat "$pid_file")
if ps -p $pid > /dev/null 2>&1; then
echo -e "${YELLOW}🛑 停止 $service_name (PID: $pid)...${NC}"
kill $pid
sleep 2
# 检查是否还在运行
if ps -p $pid > /dev/null 2>&1; then
echo -e "${RED}⚠️ 强制停止 $service_name...${NC}"
kill -9 $pid
fi
echo -e "${GREEN}$service_name 已停止${NC}"
else
echo -e "${BLUE} $service_name 未运行${NC}"
fi
rm -f "$pid_file"
else
echo -e "${BLUE} $service_name PID文件不存在${NC}"
fi
}
# 主函数
main() {
# 检查logs目录是否存在
if [ ! -d "logs" ]; then
echo -e "${BLUE} 没有找到运行中的服务${NC}"
exit 0
fi
# 停止各个服务
stop_service "前端服务" "logs/frontend.pid"
stop_service "后端服务" "logs/backend.pid"
stop_service "Spark数据处理器" "logs/spark.pid"
# 清理端口(如果需要)
echo -e "${YELLOW}🧹 清理可能占用的端口...${NC}"
# 检查并杀死可能占用8080端口的进程
local backend_port_pid=$(lsof -ti:8080 2>/dev/null)
if [ ! -z "$backend_port_pid" ]; then
echo -e "${YELLOW}🛑 停止占用8080端口的进程...${NC}"
kill $backend_port_pid 2>/dev/null
fi
# 检查并杀死可能占用3000端口的进程
local frontend_port_pid=$(lsof -ti:3000 2>/dev/null)
if [ ! -z "$frontend_port_pid" ]; then
echo -e "${YELLOW}🛑 停止占用3000端口的进程...${NC}"
kill $frontend_port_pid 2>/dev/null
fi
echo ""
echo -e "${GREEN}🎉 农业股票数据分析系统已完全停止!${NC}"
echo "=========================================="
echo -e "${BLUE}📝 日志文件已保留在logs目录中${NC}"
echo -e "${BLUE}🔄 重新启动系统: ./start-system.sh${NC}"
echo "=========================================="
}
# 执行主函数
main