#!/bin/bash # DATUM Gateway health check — managed by Ansible (roles/datum_gateway) # # The exit code is the answer and systemd keeps it: # systemctl is-failed datum-gateway-healthcheck.service # Reporting anywhere else is optional and generic. PUSH_URL="${HEALTHCHECK_PUSH_URL:-}" PUSH_TOKEN="${HEALTHCHECK_PUSH_TOKEN:-}" STRATUM_PORT={{ datum_gateway_stratum_port }} check_datum() { # Service must be active and stratum port must be listening systemctl is-active --quiet datum-gateway && \ nc -z 127.0.0.1 "${STRATUM_PORT}" } report() { local status=$1 local msg=$2 # No push URL is normal, not an error: the exit code below is still a # complete answer for anything reading unit state. [ -n "$PUSH_URL" ] || return 0 # Gatus external endpoint: a POST with a bearer token, NOT Uptime Kuma's # GET with ?status=up. The callers still pass up/down, so the mapping is # done here rather than at every call site. local _ok=false [ "${status}" = "up" ] && _ok=true curl -s --max-time 15 --retry 2 -o /dev/null -X POST \ -H "Authorization: Bearer ${PUSH_TOKEN}" \ "${PUSH_URL}?success=${_ok}&error=${msg// /%20}" || true } if check_datum; then report "up" "OK" exit 0 else report "down" "DATUM Gateway not responding" exit 1 fi