35 lines
1.1 KiB
Text
35 lines
1.1 KiB
Text
|
|
#!/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:-}"
|
||
|
|
|
||
|
|
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
|
||
|
|
curl -s --max-time 10 --retry 2 -o /dev/null \
|
||
|
|
"${PUSH_URL}?status=${status}&msg=${msg// /%20}&ping=" || 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
|