98 lines
3.2 KiB
Bash
Executable File
Raw 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
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
REPO_ROOT="$(cd "$TEST_ROOT/../../.." && pwd)"
compose() {
if docker compose version >/dev/null 2>&1; then
docker compose "$@"
else
docker-compose "$@"
fi
}
echo "[INFO] Bringing up system stack..."
# 加载 .env 以获取端口(由 01_bootstrap 生成)
if [[ -f "$TEST_ROOT/.env" ]]; then
set -a; source "$TEST_ROOT/.env"; set +a
fi
REQUEST_GPU=${ARGUS_SYS_ENABLE_GPU:-false}
GPU_AVAILABLE=false
GPU_CHECK_SCRIPT="$REPO_ROOT/src/metric/tests/scripts/common/check-gpu.sh"
if [[ "$REQUEST_GPU" == "true" ]]; then
echo "[INFO] --enable-gpu 生效,验证主机 GPU..."
if [[ -f "$GPU_CHECK_SCRIPT" ]]; then
if bash "$GPU_CHECK_SCRIPT" >/dev/null 2>&1; then
GPU_AVAILABLE=true
echo "[INFO] GPU 检测通过,将启动 gpu profile"
else
echo "[ERROR] 主机缺少可用 GPU无法继续 --enable-gpu 流程" >&2
exit 1
fi
else
echo "[ERROR] 未找到 GPU 检测脚本: $GPU_CHECK_SCRIPT" >&2
exit 1
fi
else
echo "[INFO] 未启用 GPU 流程"
fi
pushd "$TEST_ROOT" >/dev/null
compose -p argus-sys down --remove-orphans || true
# 清理可能由 08 脚本创建的同名容器,避免 compose up 冲突
for name in argus-node-b; do
if docker ps -aqf "name=^${name}$" >/dev/null 2>&1 && [[ -n "$(docker ps -aqf "name=^${name}$")" ]]; then
docker rm -f "$name" >/dev/null 2>&1 || true
fi
done
# 预检:检查多端口网关所需宿主端口是否空闲
check_port_free() {
local p="$1"
if ss -ltnp 2>/dev/null | grep -q ":${p} "; then
echo "[ERR] Host port ${p} is already in use. Please free it before running 02_up.sh" >&2
ss -ltnp | awk -v p=":${p} " '$0 ~ p {print " " $0}' || true
return 1
fi
return 0
}
for port in \
"${WEB_PROXY_PORT_8080:-8080}" \
"${WEB_PROXY_PORT_8081:-8081}" \
"${WEB_PROXY_PORT_8082:-8082}" \
"${WEB_PROXY_PORT_8083:-8083}" \
"${WEB_PROXY_PORT_8084:-8084}" \
"${WEB_PROXY_PORT_8085:-8085}"; do
check_port_free "$port" || { echo "[ERR] Required port busy: $port"; exit 1; }
done
# 根据GPU可用性决定启动的服务
if [[ "$GPU_AVAILABLE" == true ]]; then
echo "[INFO] 启动所有服务(包含 gpu profile..."
compose -p argus-sys --profile gpu up -d || true
else
echo "[INFO] 启动基础服务(不含 gpu profile..."
compose -p argus-sys up -d || true
fi
# 若 web-proxy 处于 Created 状态,尝试单独启动一次(处理偶发 Address already in use 后端已释放的场景)
if docker ps -a --format '{{.Names}}\t{{.Status}}' | grep -q '^argus-web-proxy\s\+Created'; then
echo "[WARN] web-proxy in Created state; retry starting it..."
docker start argus-web-proxy || true
fi
popd >/dev/null
if [[ "$GPU_AVAILABLE" == true ]]; then
echo "[OK] Services started: master:${MASTER_PORT:-32300} es:${ES_HTTP_PORT:-9200} kibana:${KIBANA_PORT:-5601} node-a:${NODE_A_PORT:-2020} node-b:${NODE_B_PORT:-2021} test-gpu-node:172.31.0.51"
else
echo "[OK] Services started: master:${MASTER_PORT:-32300} es:${ES_HTTP_PORT:-9200} kibana:${KIBANA_PORT:-5601} node-a:${NODE_A_PORT:-2020} node-b:${NODE_B_PORT:-2021} (gpu skipped)"
fi