2026-10-04 18:32:44 +00:00
|
|
|
#!/bin/bash
|
2026-10-06 19:28:29 +00:00
|
|
|
# relay-health-check.sh — check all registry CDP relay endpoints on bl.
|
2026-10-04 18:32:44 +00:00
|
|
|
# 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"
|
|
|
|
|
|
2026-10-06 19:28:29 +00:00
|
|
|
# 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
|
2026-10-04 18:32:44 +00:00
|
|
|
FAILED=0
|
2026-10-06 19:28:29 +00:00
|
|
|
# shellcheck disable=SC2086 (intended word splitting: one node per word)
|
|
|
|
|
for node in $NODES; do
|
2026-10-04 18:32:44 +00:00
|
|
|
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
|