Files
deploy-test/05-start.sh
2026-04-13 01:27:34 +07:00

139 lines
4.4 KiB
Bash
Executable File
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
# =============================================================================
# 05-start.sh — 启动后端 Go 服务
#
# 用法:
# ./05-start.sh # 按依赖顺序启动全部服务
# ./05-start.sh <svc> # 只启动指定服务
#
# 启动顺序(有依赖关系):
# openim-server → chat-rpc / admin-rpc → chat-api / admin-api
# → meetingmsg / livecloud / livestream
#
# 日志文件: .local-dev/logs/<service>.log
# PID 文件: .local-dev/pids/<service>.pid
# =============================================================================
set -euo pipefail
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh"
load_env
init_dirs
init_script_log # ← 脚本执行日志
header "步骤 5 / 5 — 启动后端服务"
TARGET="${1:-all}"
# ── 服务启动配置 ─────────────────────────────────────────────────────────────
# 格式: svc_workdir[name] svc_args[name]
declare -A svc_workdir=(
[openim-server]="$ROOT_DIR/open-im-server"
[chat-rpc]="$ROOT_DIR/chat"
[admin-rpc]="$ROOT_DIR/chat"
[chat-api]="$ROOT_DIR/chat"
[admin-api]="$ROOT_DIR/chat"
[meetingmsg]="$ROOT_DIR/meetingmsg"
[livecloud]="$ROOT_DIR/livecloud"
[livestream]="$ROOT_DIR/livestream"
[build-server]="$ROOT_DIR/build-server"
)
declare -A svc_args=(
[openim-server]="-c $ROOT_DIR/open-im-server/config"
[chat-rpc]="-c $ROOT_DIR/chat/config"
[admin-rpc]="-c $ROOT_DIR/chat/config"
[chat-api]="-c $ROOT_DIR/chat/config"
[admin-api]="-c $ROOT_DIR/chat/config"
[meetingmsg]=""
[livecloud]=""
[livestream]=""
[build-server]=""
)
declare -A svc_desc=(
[openim-server]=":10002 (API) :10001 (MsgGateway WS)"
[chat-rpc]="内部 RPC"
[admin-rpc]="内部 RPC"
[chat-api]=":10008"
[admin-api]=":10009"
[meetingmsg]=":8000 (WS)"
[livecloud]=":8080"
[livestream]=":8081"
[build-server]=":8281"
)
_start_one() {
local svc="$1"
start_svc "$svc" \
"$BUILD_DIR/$svc" \
"${svc_args[$svc]}" \
"${svc_workdir[$svc]}"
}
# ── 启动全部(有序) ──────────────────────────────────────────────────────────
_start_all() {
step "第 1 组: openim-server核心 IM 服务)"
_start_one openim-server
info "等待 openim-server 将 RPC 注册到 Etcd... (8s)"
sleep 8
step "第 2 组: chat RPC 服务"
_start_one chat-rpc
_start_one admin-rpc
info "等待 chat RPC 注册到 Etcd... (4s)"
sleep 4
step "第 3 组: chat API 服务"
_start_one chat-api
_start_one admin-api
step "第 4 组: 业务服务"
_start_one meetingmsg
_start_one livecloud
_start_one livestream
_start_one build-server
echo ""
echo -e "${BOLD}服务汇总:${NC}"
for svc in openim-server chat-rpc admin-rpc chat-api admin-api meetingmsg livecloud livestream build-server; do
print_svc_status "$svc" "${svc_desc[$svc]}"
done
echo ""
echo -e "${BOLD}常用地址:${NC}"
echo " IM API: http://localhost:10002"
echo " IM WebSocket: ws://localhost:10001"
echo " Chat API: http://localhost:10008"
echo " Admin API: http://localhost:10009"
echo " MeetingMsg WS: ws://localhost:8000"
echo " Livecloud: http://localhost:8080"
echo " Livestream: http://localhost:8081"
echo " Build Server: http://localhost:8281"
echo ""
echo -e "${BOLD}查看日志:${NC}"
echo -e " ${CYAN}./deploy-test/logs.sh openim-server${NC}"
echo -e " ${CYAN}./deploy-test/logs.sh chat-api${NC}"
}
# ── 启动单个 ──────────────────────────────────────────────────────────────────
_start_single() {
local svc="$1"
if [[ -z "${svc_workdir[$svc]:-}" ]]; then
error "未知服务: $svc"
echo "可用: ${!svc_workdir[*]}"
exit 1
fi
step "启动: $svc"
_start_one "$svc"
echo ""
print_svc_status "$svc" "${svc_desc[$svc]}"
}
# ── 入口 ─────────────────────────────────────────────────────────────────────
if [[ "$TARGET" == "all" ]]; then
_start_all
else
_start_single "$TARGET"
fi