#!/bin/bash # Fulcrum health check — managed by Ansible (roles/fulcrum) # # Checks that Fulcrum's Electrum TCP port is accepting connections, and records # the answer in the exit code, which systemd keeps: # systemctl is-failed fulcrum-healthcheck.service # That is a complete answer with no monitoring system involved. Reporting # elsewhere is optional and generic — set healthcheck_push_url. FULCRUM_HOST="{{ fulcrum_tcp_bind }}" FULCRUM_PORT={{ fulcrum_tcp_port }} PUSH_URL="${HEALTHCHECK_PUSH_URL:-}" PUSH_TOKEN="${HEALTHCHECK_PUSH_TOKEN:-}" check_fulcrum() { timeout 5 bash -c "echo > /dev/tcp/${FULCRUM_HOST}/${FULCRUM_PORT}" 2>/dev/null } report() { local status=$1 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_fulcrum; then report "up" "OK" exit 0 else echo "Fulcrum TCP port ${FULCRUM_PORT} not responding" report "down" "Fulcrum TCP port not responding" exit 1 fi