2026-03-20 21:01:26 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# =============================================================================
|
|
|
|
|
# /opt/timmy-tower/health-check.sh
|
|
|
|
|
# Run by systemd timer every 5 minutes.
|
2026-03-20 21:07:32 +00:00
|
|
|
# Restarts timmy-tower if /api/healthz returns non-200.
|
2026-03-20 21:01:26 +00:00
|
|
|
# =============================================================================
|
2026-03-20 21:07:32 +00:00
|
|
|
HEALTH_URL="http://localhost:8088/api/healthz"
|
2026-03-20 21:01:26 +00:00
|
|
|
LOG="/opt/timmy-tower/health.log"
|
|
|
|
|
|
|
|
|
|
log() { echo "[$(date -u +%FT%TZ)] [health] $*" | tee -a "$LOG"; }
|
|
|
|
|
|
|
|
|
|
if curl -sf --max-time 10 "$HEALTH_URL" > /dev/null; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
log "Health check FAILED — restarting timmy-tower"
|
|
|
|
|
systemctl restart timmy-tower
|
|
|
|
|
sleep 5
|
|
|
|
|
|
|
|
|
|
if curl -sf --max-time 10 "$HEALTH_URL" > /dev/null; then
|
|
|
|
|
log "Service recovered after restart"
|
|
|
|
|
else
|
|
|
|
|
log "CRITICAL: service did not recover after restart — manual intervention needed"
|
|
|
|
|
fi
|