#!/usr/bin/env bash # Shared paths and settings for every script in this directory. Source this, don't run it. export EC_DB_TCP_PORT="${EC_DB_TCP_PORT:-9092}" export EC_DB_NAME="${EC_DB_NAME:-expand-contract}" EC_DB_BASE_DIR="${EC_DB_BASE_DIR:-/tmp/ec-demo/db}" EC_RUN_DIR="${EC_RUN_DIR:-/tmp/ec-demo}" EC_LOG_DIR="$EC_RUN_DIR/logs" EC_PID_DIR="$EC_RUN_DIR/pids" EC_PHASE_FILE="$EC_RUN_DIR/phase.txt" EC_LOAD_SUMMARY="$EC_RUN_DIR/load-summary.txt" PORT_A=8081 PORT_B=8082 MODULE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" JAR="$MODULE_DIR/target/db-migrations-expand-contract-1.0.0.jar" CP_FILE="$MODULE_DIR/cp.txt" mkdir -p "$EC_LOG_DIR" "$EC_PID_DIR" "$EC_DB_BASE_DIR" wait_db_server() { local tries="${1:-40}" for i in $(seq 1 "$tries"); do if (echo > "/dev/tcp/localhost/$EC_DB_TCP_PORT") >/dev/null 2>&1; then return 0 fi sleep 0.25 done echo "H2 TCP server on port $EC_DB_TCP_PORT never came up" >&2 return 1 } set_phase() { echo -n "$1" > "$EC_PHASE_FILE" echo "[phase] $1" } wait_healthy() { local port="$1" local tries="${2:-40}" for i in $(seq 1 "$tries"); do code=$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:$port/actuator/health" || true) if [ "$code" = "200" ]; then return 0 fi sleep 0.5 done echo "instance on port $port never became healthy" >&2 return 1 } wait_down() { local port="$1" local tries="${2:-20}" for i in $(seq 1 "$tries"); do code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 1 "http://localhost:$port/actuator/health" || true) if [ "$code" != "200" ]; then return 0 fi sleep 0.3 done return 1 }