nomadro/deploy/observability/healthcheck.sh
eric 9f8fec1723 Ship portal PC/H5 acceptance, VIP ScrollReader, admin analytics and ops anchors.
Adds /api/health, ntfy notify on config save, /admin/analytics charts, and deploy smoke for miniprogram config/API.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 23:52:00 -05:00

38 lines
1.8 KiB
Bash

#!/bin/bash
# Healthcheck key public services; notify ntfy on failure transitions.
set -euo pipefail
STATE_DIR=/var/lib/nomadro-health
NOTIFY=/usr/local/bin/notify-ntfy
mkdir -p "$STATE_DIR"
check() {
local name="$1"
local cmd="$2"
local ok=0
if eval "$cmd" >/dev/null 2>&1; then
ok=1
fi
local state_file="$STATE_DIR/${name}.ok"
local prev=1
[[ -f "$state_file" ]] && prev=$(cat "$state_file")
echo "$ok" >"$state_file"
if [[ "$ok" -eq 0 && "$prev" -eq 1 ]]; then
"$NOTIFY" "Service down: $name" "Host $(hostname) — $name failed health check at $(date -u +%Y-%m-%dT%H:%M:%SZ)" high "rotating_light,server" || true
elif [[ "$ok" -eq 1 && "$prev" -eq 0 ]]; then
"$NOTIFY" "Service recovered: $name" "Host $(hostname) — $name is healthy again" default "white_check_mark,server" || true
fi
}
check caddy "systemctl is-active --quiet caddy || systemctl is-active --quiet nginx"
check docker "systemctl is-active --quiet docker"
check nomadro "systemctl is-active --quiet nomadro"
check portal-health "curl -fsS -o /dev/null http://127.0.0.1:4003/api/health"
check portal-config "curl -fsS http://127.0.0.1:4003/api/config | grep -q '\"modules\"'"
check umami "curl -fsS -o /dev/null http://127.0.0.1:3010/api/heartbeat || curl -fsS -o /dev/null https://umami.nomadro.cn/api/heartbeat"
check ntfy "curl -fsS http://127.0.0.1:2586/v1/health | grep -q healthy || curl -fsS https://ntfy.nomadro.cn/v1/health | grep -q healthy"
check public-nomadro "curl -fsS -o /dev/null https://nomadro.cn/api/health"
check public-api "curl -fsS -o /dev/null -m 15 https://api.nomadro.cn/ || curl -fsS -o /dev/null -m 15 https://api.nomadro.cn/docs"
check public-umami "curl -fsS -o /dev/null https://umami.nomadro.cn/api/heartbeat"
check public-ntfy "curl -fsS https://ntfy.nomadro.cn/v1/health | grep -q healthy"