Files
box/bin/relay-health-check.sh
T

44 lines
1.3 KiB
Bash
Raw Normal View History

#!/bin/bash
# relay-health-check.sh — check all registry CDP relay endpoints on bl.
# Self-contained: no nested SSH quoting. Sources pinned ports from netvm-names.sh.
#
# Output: "name:code" per relay on stdout.
# Exit 0 if all return 200; exit 1 otherwise (lists failures on stderr).
#
# Called by the cdp-relay-health-monitor cron and by `box-ctl.py relay-health`.
set -u
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=/dev/null
source "$SCRIPT_DIR/netvm-names.sh"
# Registry-driven node list (was hardcoded 4 nodes; def/dev had no
# relay-health coverage — 2026-10-06).
watched_nodes() {
"$SCRIPT_DIR/netvm-registry.py" 2>/dev/null | cut -d: -f1
}
# Allow sourcing for tests without running checks.
if [ "${RELAY_HEALTH_CHECK_LIB_ONLY:-}" = "1" ]; then
return 0 2>/dev/null || exit 0
fi
NODES="$(watched_nodes)"
if [ -z "$NODES" ]; then
echo "node registry empty/unreadable" >&2
exit 1
fi
FAILED=0
# shellcheck disable=SC2086 (intended word splitting: one node per word)
for node in $NODES; do
netvm_names "$node"
url="http://${PEER_IP}:${CDP_PORT}/json/version"
code=$(curl -s -m 8 -o /dev/null -w "%{http_code}" "$url" 2>/dev/null || echo "000")
echo "${node}:${code}"
if [ "$code" != "200" ]; then
echo "FAIL: ${node} relay ${PEER_IP}:${CDP_PORT} returned ${code}" >&2
FAILED=1
fi
done
exit $FAILED