Files
AIRegulation-Deployment/scripts/03_start_infra.sh
2026-04-23 09:58:47 +08:00

94 lines
3.8 KiB
Bash
Raw Permalink 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.

#!/usr/bin/env bash
# ══════════════════════════════════════════════════
# 03_start_infra.sh
# 分步启动基础设施(含健康等待),顺序:
# PostgreSQL + Redis → etcd + MinIO → Milvus → Neo4j
# 用法bash scripts/03_start_infra.sh
# ══════════════════════════════════════════════════
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
cd "$PROJECT_DIR"
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
info() { echo -e "${BLUE}[INFO]${NC} $*"; }
ok() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*"; exit 1; }
# 等待服务健康的函数
wait_healthy() {
local service=$1
local max_wait=${2:-120}
local interval=5
local elapsed=0
info "等待 $service 健康就绪..."
while [[ $elapsed -lt $max_wait ]]; do
local status
status=$(docker compose ps --format json "$service" 2>/dev/null | \
python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('Health','unknown'))" 2>/dev/null || echo "unknown")
if [[ "$status" == "healthy" ]]; then
ok "$service 已就绪"
return 0
fi
echo -n "."
sleep $interval
elapsed=$((elapsed + interval))
done
echo ""
error "$service 等待超时(${max_wait}s请检查docker compose logs $service"
}
info "══════════════════════════════════════════"
info " 启动基础设施层"
info "══════════════════════════════════════════"
# ── Step 1PostgreSQL + Redis ──────────────────
info "Step 1/4启动 PostgreSQL 和 Redis..."
docker compose up -d postgres redis
wait_healthy postgres 90
wait_healthy redis 30
ok "数据层就绪"
# ── Step 2etcd + MinIOMilvus 依赖)─────────
info "Step 2/4启动 etcd 和 MinIOMilvus 依赖)..."
docker compose up -d etcd minio
wait_healthy etcd 60
wait_healthy minio 60
ok "对象存储层就绪"
# ── Step 3Milvus ──────────────────────────────
info "Step 3/4启动 Milvus向量数据库..."
docker compose up -d milvus
info "Milvus 初始化需要约 60 秒,请耐心等待..."
wait_healthy milvus 180
ok "Milvus 就绪"
# ── Step 4Neo4j ───────────────────────────────
info "Step 4/4启动 Neo4j知识图谱..."
docker compose up -d neo4j
wait_healthy neo4j 120
ok "Neo4j 就绪"
# ── 汇总 ────────────────────────────────────────
echo ""
echo -e "${GREEN}══════════════════════════════════════════${NC}"
echo -e "${GREEN} 基础设施启动完成!${NC}"
echo -e "${GREEN}══════════════════════════════════════════${NC}"
echo ""
echo " PostgreSQL : localhost:5432"
echo " Redis : localhost:6379"
echo " Milvus : localhost:19530 (gRPC), localhost:9091 (HTTP)"
echo " Neo4j : localhost:7474 (Browser), localhost:7687 (Bolt)"
echo " MinIO 控制台: localhost:9001 (admin/minioadmin)"
echo ""
echo "下一步bash scripts/04_build_services.sh"