#!/usr/bin/env bash # scripts/healthcheck.sh — health check stack + APIs internes set -euo pipefail DOCMOST_URL="${DOCMOST_URL:-http://localhost:3000}" BASEROW_URL="${BASEROW_URL:-http://localhost:8080}" BRIDGE_URL="${BRIDGE_URL:-}" TIMEOUT="${HEALTHCHECK_TIMEOUT:-10}" red() { printf '\033[31m%s\033[0m\n' "$1"; } green() { printf '\033[32m%s\033[0m\n' "$1"; } yellow(){ printf '\033[33m%s\033[0m\n' "$1"; } check_http() { local name="$1" local url="$2" if curl -sf --max-time "$TIMEOUT" -o /dev/null "$url"; then green " OK $name : $url" return 0 else red " KO $name : $url" return 1 fi } check_health_endpoint() { local name="$1" local url="$2" local expected="$3" local resp resp=$(curl -sf --max-time "$TIMEOUT" "$url" || echo "") if echo "$resp" | grep -q "$expected"; then green " OK $name (API health endpoint)" return 0 else red " KO $name (API health endpoint) — got: ${resp:0:80}" return 1 fi } echo "Healthcheck stack (timeout ${TIMEOUT}s)" echo "----------------------------------------" ok=0 total=0 ((++total)) || true check_http "Docmost UI " "$DOCMOST_URL" && ((++ok)) || true ((++total)) || true check_health_endpoint "Docmost API" "$DOCMOST_URL/api/health" "ok" && ((++ok)) || true ((++total)) || true check_http "Baserow UI " "$BASEROW_URL" && ((++ok)) || true ((++total)) || true check_http "Baserow API" "$BASEROW_URL/api/_health/" && ((++ok)) || true if [ -n "$BRIDGE_URL" ]; then ((++total)) || true check_health_endpoint "Bridge " "$BRIDGE_URL/api/health" "ok" && ((++ok)) || true fi # Container status (si Docker dispo) if command -v docker >/dev/null 2>&1; then echo "" echo "Containers :" docker compose ps --format " {{.Name}}: {{.Status}}" 2>&1 | head -10 || yellow " (compose not running here)" fi echo "----------------------------------------" if [ "$ok" -eq "$total" ]; then green "Healthcheck : $ok/$total OK" exit 0 else red "Healthcheck : $ok/$total OK" exit 1 fi