#!/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" if [[ -f "$ENV_FILE" ]]; then set -a # shellcheck source=/dev/null source "$ENV_FILE" set +a fi DEPLOY_TEST_IP="${DEPLOY_TEST_IP:-127.0.0.1}" normalize_pc_proxy_env 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}" printf " ${CYAN}◉${NC} %-10s Kafka 外网 bootstrap(EXTERNAL)%s:%s TCP PLAINTEXT\n" "" "${DEPLOY_TEST_IP:-?}" "${KAFKA_EXTERNAL_PORT:-9094}" print_container_status "Etcd" "dev-etcd" "${ETCD_PORT:-2379}" print_container_status "MinIO" "dev-minio" "${MINIO_API_PORT:-9000}" 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" "MinIO" \ "bucket=${MINIO_BUCKET:-?} external=${MINIO_EXTERNAL_ADDRESS:-?}" # ── 后端服务 ───────────────────────────────────────────────────────────────── 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" ":8888" print_svc_status "build-server" ":8281" # ── Nginx API / WebSocket 网关 ───────────────────────────────────────────────── echo "" echo -e "${BOLD}[ Nginx 网关(PC API / WebSocket)]${NC}" if command -v curl &>/dev/null && [[ -n "${PC_BACKEND_ORIGIN:-}" ]]; then PC_BACKEND_ORIGIN="${PC_BACKEND_ORIGIN%/}" curl_tls=() [[ "$PC_BACKEND_ORIGIN" == https://* ]] && curl_tls=(-k) if curl "${curl_tls[@]}" -fsS --max-time 3 "${PC_BACKEND_ORIGIN}/nginx-health" >/dev/null 2>&1; then printf " ${GREEN}●${NC} %-14s %s\n" "nginx-health" "${PC_BACKEND_ORIGIN}/nginx-health" else printf " ${RED}○${NC} %-14s %s\n" "nginx-health" "${PC_BACKEND_ORIGIN}/nginx-health 不可达" echo " 请执行: sudo ./deploy-test/00-init-tools.sh nginx,并确认安全组/防火墙放行 TCP 80" fi gateway_host=$(printf '%s' "$PC_BACKEND_ORIGIN" | sed -E 's#^https?://([^/]+).*#\1#') if [[ "$PC_BACKEND_ORIGIN" == https://* ]]; then default_ws_url="wss://${gateway_host}/msg_gateway" else default_ws_url="ws://${gateway_host}/msg_gateway" fi echo " PC IM API: ${PC_VITE_API_URL:-${PC_BACKEND_ORIGIN}/api/im}" echo " PC User API: ${PC_VITE_USER_URL:-${PC_BACKEND_ORIGIN}/api/user}" echo " PC Chat API: ${PC_VITE_CHAT_URL:-${PC_BACKEND_ORIGIN}/api/chat}" echo " PC Admin API: ${PC_VITE_ADMIN_URL:-${PC_BACKEND_ORIGIN}/api/admin}" echo " PC WebSocket: ${PC_VITE_WS_URL:-$default_ws_url}" echo " PC 页面入口: ${PC_BACKEND_ORIGIN}/ (外部 HTTPS → 本机 Nginx :80 → pc dev:web :5173)" echo " Nginx 日志: /var/log/nginx/openim-pc-proxy-access.log" pc_probe_msg_gateway "$PC_BACKEND_ORIGIN" else printf " ${YELLOW}○${NC} %-14s %s\n" "nginx-health" "跳过(未安装 curl 或未设置 PC_BACKEND_ORIGIN)" fi # ── 前端服务 ───────────────────────────────────────────────────────────────── echo "" echo -e "${BOLD}[ 前端开发服务器 ]${NC}" fe_port_desc() { case "$1" in pc) echo "5173 (yarn dev:web)" ;; meetingh5) echo "5188" ;; h5) echo "3003" ;; cms) echo "8001" ;; build-cms) echo "8002" ;; build-down) echo "8003" ;; *) echo "?" ;; esac } for fe in pc meetingh5 h5 cms build-cms build-down; do pidfile="$PID_DIR/fe-${fe}.pid" logfile="$LOG_DIR/fe-${fe}.log" port_desc="$(fe_port_desc "$fe")" if [[ -f "$pidfile" ]] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then printf " ${GREEN}●${NC} %-14s PID=%-7s :%s\n" "$fe" "$(cat "$pidfile")" "$port_desc" else printf " ${RED}○${NC} %-14s 未运行 :%s\n" "$fe" "$port_desc" fi done # ── 端口占用检查 ────────────────────────────────────────────────────────────── echo "" echo -e "${BOLD}[ 端口占用 ]${NC}" PORTS=(10002 10001 10008 10009 8000 8080 8888 8281 5173 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 ""