#!/usr/bin/env bash # ============================================================================= # status.sh — 查看所有服务运行状态 # # 显示内容: # - Docker 容器状态(Redis/Kafka/Etcd) # - 远程服务配置摘要(MongoDB/S3) # - 后端服务进程状态(PID + 监听端口) # ============================================================================= set -euo pipefail source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh" load_env 2>/dev/null || true header "服务运行状态" # ── Docker 基础设施 ─────────────────────────────────────────────────────────── echo "" echo -e "${BOLD}[ Docker 基础设施 ]${NC}" print_container_status "Redis" "dev-redis" "${REDIS_PORT:-6379}" print_container_status "Kafka" "dev-kafka" "${KAFKA_PORT:-9092}" print_container_status "Etcd" "dev-etcd" "${ETCD_PORT:-2379}" print_container_status "LiveKit" "dev-livekit" "7880" printf " ${CYAN}◉${NC} %-10s 公网 %s:50000-51000/udp (WebRTC)\n" "" "${LIVEKIT_NODE_IP:-?}" # ── 远程服务 ───────────────────────────────────────────────────────────────── echo "" echo -e "${BOLD}[ 远程服务(连接配置)]${NC}" printf " ${CYAN}◉${NC} %-10s %s\n" "MongoDB" \ "${MONGO_HOST:-?}:${MONGO_PORT:-27017}/${MONGO_DATABASE:-?} (authSource=${MONGO_AUTHSOURCE:-?})" printf " ${CYAN}◉${NC} %-10s %s\n" "S3" \ "s3://${AWS_BUCKET:-?} region=${AWS_REGION:-?}" # ── 后端服务 ───────────────────────────────────────────────────────────────── echo "" echo -e "${BOLD}[ 后端服务 ]${NC}" print_svc_status "openim-server" ":10002 (API) :10001 (MsgGateway WS)" print_svc_status "chat-rpc" "内部 RPC → Etcd" print_svc_status "admin-rpc" "内部 RPC → Etcd" print_svc_status "chat-api" ":10008" print_svc_status "admin-api" ":10009" print_svc_status "meetingmsg" ":8000 (WS)" print_svc_status "livecloud" ":8080" print_svc_status "livestream" ":8081" print_svc_status "build-server" ":8281" # ── 前端服务 ───────────────────────────────────────────────────────────────── echo "" echo -e "${BOLD}[ 前端开发服务器 ]${NC}" declare -A FE_PORT_MAP=( [pc]="7777 (Electron Vite)" [meetingh5]="5188" [h5]="3003" [cms]="8001" [build-cms]="8002" [build-down]="8003" ) for fe in pc meetingh5 h5 cms build-cms build-down; do pidfile="$PID_DIR/fe-${fe}.pid" logfile="$LOG_DIR/fe-${fe}.log" if [[ -f "$pidfile" ]] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then printf " ${GREEN}●${NC} %-14s PID=%-7s :%s\n" "$fe" "$(cat "$pidfile")" "${FE_PORT_MAP[$fe]}" else printf " ${RED}○${NC} %-14s 未运行 :%s\n" "$fe" "${FE_PORT_MAP[$fe]}" fi done # ── 端口占用检查 ────────────────────────────────────────────────────────────── echo "" echo -e "${BOLD}[ 端口占用 ]${NC}" PORTS=(10002 10001 10008 10009 8000 8080 8081 8281 7777 5188 3003 8001 8002 8003) for port in "${PORTS[@]}"; do pid=$(lsof -ti :"$port" 2>/dev/null | head -1 || true) if [[ -n "$pid" ]]; then cmd=$(ps -p "$pid" -o comm= 2>/dev/null || echo "?") printf " ${GREEN}●${NC} :%d PID=%-6s (%s)\n" "$port" "$pid" "$cmd" else printf " ${YELLOW}○${NC} :%d (未监听)\n" "$port" fi done # ── 快速操作提示 ────────────────────────────────────────────────────────────── echo "" echo -e "${BOLD}[ 快捷命令 ]${NC}" echo " ./deploy-test/logs.sh 查看日志(支持前端: pc/h5/cms 等)" echo " ./deploy-test/restart.sh 重启后端服务" echo " ./deploy-test/restart.sh --build 重编译并重启" echo " ./deploy-test/07-start-frontend.sh 启动前端服务" echo " ./deploy-test/stop-frontend.sh 停止前端服务" echo " ./deploy-test/check-conn.sh 验证 MongoDB/S3 连接" echo ""