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

43 lines
1.2 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
# =============================================================================
# stop.sh — 停止后端 Go 服务
#
# 用法:
# ./stop.sh # 停止全部后端服务
# ./stop.sh <svc> # 只停止指定服务
#
# 注意:此命令只停止后端进程,不影响 Docker 容器Redis/Kafka/Etcd
# 如需停止 Docker 容器,执行: ./stop-infra.sh
# =============================================================================
set -euo pipefail
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh"
init_dirs
init_script_log # ← 脚本执行日志
TARGET="${1:-all}"
if [[ "$TARGET" == "all" ]]; then
step "停止所有后端服务"
for svc in "${ALL_SVCS[@]}"; do
stop_svc "$svc"
done
echo ""
success "所有后端服务已停止"
echo ""
echo -e "如需停止 Docker 基础设施:"
echo -e " ${CYAN}./deploy-test/stop-infra.sh${NC}"
else
step "停止服务: $TARGET"
# 验证服务名合法
local_valid=false
for svc in "${ALL_SVCS[@]}"; do
[[ "$svc" == "$TARGET" ]] && local_valid=true && break
done
if ! $local_valid; then
error "未知服务: $TARGET"
echo "可用: ${ALL_SVCS[*]}"
exit 1
fi
stop_svc "$TARGET"
fi