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

52 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# =============================================================================
# stop-infra.sh — 停止 Docker 基础设施容器
#
# 用法:
# ./stop-infra.sh # 停止 Redis / Kafka / Etcd
# ./stop-infra.sh redis # 只停止 Redis
# ./stop-infra.sh kafka # 只停止 Kafka
# ./stop-infra.sh etcd # 只停止 Etcd
#
# 注意:仅停止容器,不删除数据。重新启动执行: 03-start-infra.sh
# =============================================================================
set -euo pipefail
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh"
require_docker_running
init_script_log # ← 脚本执行日志
TARGET="${1:-all}"
_stop_container() {
local label="$1" cname="$2"
# 先停日志收集进程
stop_docker_logger "$cname"
if docker ps --format '{{.Names}}' | grep -q "^${cname}$"; then
docker stop "$cname" > /dev/null && success "$label 容器已停止 (container=$cname)"
else
warn "$label 容器未在运行 (container=$cname)"
fi
}
case "$TARGET" in
all)
step "停止所有 Docker 基础设施"
_stop_container "LiveKit" "dev-livekit"
_stop_container "Kafka" "dev-kafka"
_stop_container "Redis" "dev-redis"
_stop_container "Etcd" "dev-etcd"
echo ""
success "所有 Docker 容器已停止(数据已保留)"
echo -e " 重新启动: ${CYAN}./deploy-test/03-start-infra.sh${NC}"
;;
redis) _stop_container "Redis" "dev-redis" ;;
kafka) _stop_container "Kafka" "dev-kafka" ;;
etcd) _stop_container "Etcd" "dev-etcd" ;;
livekit) _stop_container "LiveKit" "dev-livekit" ;;
*)
error "未知组件: $TARGET"
echo "可用: redis, kafka, etcd, livekit, all"
exit 1
;;
esac