#!/bin/bash # phoenixd health check — managed by Ansible (roles/phoenixd) # # Asks the node whether it is healthy and records the answer in the exit code, # which systemd keeps: # systemctl is-failed {{ phoenixd_healthcheck_service_name }}.service # That is a complete answer on its own. Reporting anywhere else is optional. PUSH_URL="${HEALTHCHECK_PUSH_URL:-}" export PHOENIX_DATADIR="{{ phoenixd_data_dir }}" check_phoenixd() { # Service must be active and the node must answer getinfo. # phoenix-cli reads the api password from $PHOENIX_DATADIR/phoenix.conf, # but not the bind address, so pass it explicitly. systemctl is-active --quiet phoenixd && \ {{ phoenixd_bin_dir }}/phoenix-cli \ --http-bind-ip {{ phoenixd_http_bind_ip }} \ --http-bind-port {{ phoenixd_http_bind_port }} \ getinfo 2>/dev/null | grep -q '"nodeId"' } report() { local status=$1 msg=$2 # No push URL configured is NORMAL, not an error: the exit code below still # answers the question. The previous version logged ERROR here on every # single fire, once a minute, which is noise that trains you to ignore it. [ -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_phoenixd; then report "up" "OK" exit 0 else echo "phoenixd is not responding" report "down" "phoenixd not responding" exit 1 fi