#!/bin/bash # Mempool backend health check — managed by Ansible (roles/mempool) # The exit code is the answer; systemd keeps it. Reporting is optional. PUSH_URL="${HEALTHCHECK_PUSH_URL:-}" PUSH_TOKEN="${HEALTHCHECK_PUSH_TOKEN:-}" BACKEND_PORT="{{ mempool_backend_port }}" check() { curl -sf --max-time 5 "http://localhost:${BACKEND_PORT}/api/v1/backend-info" > /dev/null 2>&1 } report() { [ -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 [ "$1" = "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=${2// /%20}" || true } if check; then report up "OK"; exit 0 else echo "Mempool backend not responding"; report down "Mempool backend not responding"; exit 1; fi