#!/usr/bin/env bash set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" runtime="$root/.runtime" pid_file="$runtime/cliproxy.pid" log_file="$runtime/cliproxy.log" if [[ -f "$pid_file" ]]; then old_pid="$(cat "$pid_file" || true)" if [[ -n "$old_pid" ]] && kill -0 "$old_pid" 2>/dev/null; then echo "CPA test host is already running (PID $old_pid)." exit 0 fi fi mkdir -p "$runtime/auths" "$runtime/plugins" : >"$log_file" nohup "$runtime/cliproxy" -config "$runtime/config.yaml" \ >"$log_file" 2>&1 "$pid_file" echo "Started CPA test host (PID $pid)." for _ in $(seq 1 30); do if curl -fsS http://127.0.0.1:8317/healthz >/dev/null 2>&1; then echo 'CPA test host is ready at http://127.0.0.1:8317' exit 0 fi if ! kill -0 "$pid" 2>/dev/null; then echo 'CPA test host exited during startup.' >&2 tail -n 100 "$log_file" >&2 exit 1 fi sleep 1 done echo 'Timed out waiting for CPA test host.' >&2 tail -n 100 "$log_file" >&2 exit 1