FABRIC/scripts/fabric-health-check.sh
jedarden 038cc9348d feat(bd-ch6.6): wire sd_notify + add untracked serverMetrics and health-check files
- Add src/serverMetrics.ts (ServerMetrics class for /api/health + /api/metrics)
- Add scripts/fabric-health-check.sh (curl-based liveness probe)
- Wire sd_notify READY=1 on server start and WATCHDOG=1 keepalives in server.ts
  so the Type=notify systemd service correctly reports start and keeps the
  watchdog alive without an external npm package

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 21:58:37 -04:00

21 lines
571 B
Bash

#!/usr/bin/env bash
# FABRIC systemd health check script
# Called by systemd's WatchdogSec mechanism.
# Exits non-zero if the health endpoint reports unhealthy.
PORT="${FABRIC_PORT:-3000}"
MAX_RETRIES=3
RETRY_INTERVAL=1
for i in $(seq 1 $MAX_RETRIES); do
STATUS=$(curl -sf -o /dev/null -w '%{http_code}' "http://localhost:${PORT}/api/health" 2>/dev/null)
if [ "$STATUS" = "200" ]; then
exit 0
fi
if [ "$i" -lt "$MAX_RETRIES" ]; then
sleep $RETRY_INTERVAL
fi
done
echo "FABRIC health check failed: HTTP $STATUS after $MAX_RETRIES attempts" >&2
exit 1