#!/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:-}" 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 curl -s --max-time 10 --retry 2 -o /dev/null \ "${PUSH_URL}?status=${status}&msg=${msg// /%20}&ping=" || true } if check_datum; then report "up" "OK" exit 0 else report "down" "DATUM Gateway not responding" exit 1 fi