66 lines
2.0 KiB
Bash
Executable File
66 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
BASE_URL="${1:-http://127.0.0.1:8100}"
|
|
API_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
PYTHON_BIN="${PYTHON_BIN:-/opt/domaincheck/domainCheck/.venv/bin/python}"
|
|
SIM_SCRIPT="$API_DIR/deploy/multi-region/simulate_cluster_node.py"
|
|
RUNTIME_DIR="$API_DIR/runtime"
|
|
mkdir -p "$RUNTIME_DIR"
|
|
|
|
CONTROLLER_LOG="$RUNTIME_DIR/sim-mainland-controller.log"
|
|
WORKER_LOG="$RUNTIME_DIR/sim-mainland-worker.log"
|
|
|
|
cleanup() {
|
|
set +e
|
|
if [ -n "${CTRL_PID:-}" ]; then kill "$CTRL_PID" >/dev/null 2>&1 || true; fi
|
|
if [ -n "${WORKER_PID:-}" ]; then kill "$WORKER_PID" >/dev/null 2>&1 || true; fi
|
|
"$PYTHON_BIN" "$SIM_SCRIPT" --node-code mainland-controller-sim --region mainland --role control --clear >/dev/null 2>&1 || true
|
|
"$PYTHON_BIN" "$SIM_SCRIPT" --node-code mainland-worker-sim-01 --region mainland --role worker --clear >/dev/null 2>&1 || true
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
echo "[1/4] start simulated mainland controller"
|
|
"$PYTHON_BIN" "$SIM_SCRIPT" \
|
|
--node-code mainland-controller-sim \
|
|
--region mainland \
|
|
--role control \
|
|
--status online \
|
|
--detail "模拟大陆 controller 联调节点" \
|
|
--interval 15 >"$CONTROLLER_LOG" 2>&1 &
|
|
CTRL_PID=$!
|
|
|
|
echo "[2/4] start simulated mainland worker"
|
|
"$PYTHON_BIN" "$SIM_SCRIPT" \
|
|
--node-code mainland-worker-sim-01 \
|
|
--region mainland \
|
|
--role worker \
|
|
--status busy \
|
|
--current-load 1 \
|
|
--phase "running" \
|
|
--detail "模拟大陆 worker 执行中" \
|
|
--job-id 1 \
|
|
--job-code "detect-simulated-cluster" \
|
|
--cycle-token "simcycle001" \
|
|
--active-threads 5 \
|
|
--available-proxy-count 12 \
|
|
--interval 15 >"$WORKER_LOG" 2>&1 &
|
|
WORKER_PID=$!
|
|
|
|
sleep 2
|
|
|
|
echo "[3/4] runtime readiness"
|
|
curl -fsS "${BASE_URL}/api/v1/runtime/readiness"
|
|
echo
|
|
echo
|
|
|
|
echo "[4/4] runtime cluster summary"
|
|
curl -fsS "${BASE_URL}/api/v1/runtime/cluster"
|
|
echo
|
|
echo
|
|
echo "simulated nodes running:"
|
|
echo " controller log: $CONTROLLER_LOG"
|
|
echo " worker log: $WORKER_LOG"
|
|
echo "press Ctrl+C to stop simulation and clean up"
|
|
wait
|