#!/bin/bash
# Restarts tsvalid.service if /tsvalid/health doesn't respond promptly.
# Uses a short timeout so a wedged (but "active") service gets caught fast.

URL="http://127.0.0.1:1080/tsvalid/health"
TIMEOUT=5

if ! curl -sf --max-time "$TIMEOUT" "$URL" > /dev/null 2>&1; then
    logger -t tsvalid-healthcheck "Health check failed — restarting tsvalid.service"
    systemctl restart tsvalid.service
fi
