#!/bin/bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" INFRA_DIR="$(dirname "$SCRIPT_DIR")" echo "=== EifelDC Health Check ===" echo "" OK=true check_service() { local name=$1 local url=$2 local expected_status=${3:-200} if curl -sf -o /dev/null -w "%{http_code}" "${url}" 2>/dev/null | grep -q "${expected_status}"; then echo " [OK] ${name}" else echo " [FAIL] ${name} - ${url}" OK=false fi } if command -v docker &>/dev/null && [ -f "${INFRA_DIR}/docker-compose.yml" ]; then echo "[Docker Mode]" echo "" echo "Container Status:" cd "${INFRA_DIR}" docker compose ps echo "" echo "Service Health:" check_service "EifelDC Server" "http://localhost:3000/api/current-user" "401" check_service "Synapse" "http://localhost:8008/_matrix/client/versions" check_service "PostgreSQL" "localhost:5432" echo "" echo "Container Logs (last 5 lines):" for svc in eifeldc synapse postgres nginx; do if docker compose ps --services --filter "status=running" | grep -q "${svc}"; then echo "--- ${svc} ---" docker compose logs --tail=5 "${svc}" 2>/dev/null || true fi done else echo "[Native Mode]" echo "" echo "Service Health:" check_service "EifelDC Server" "http://localhost:3000/api/current-user" "401" check_service "Synapse" "http://localhost:8008/_matrix/client/versions" check_service "Nginx" "http://localhost:80/" echo "" echo "Systemd Status:" for svc in eifeldc-synapse eifeldc-server coturn nginx; do status=$(systemctl is-active "${svc}" 2>/dev/null || echo "unknown") if [ "$status" = "active" ]; then echo " [OK] ${svc}: ${status}" else echo " [FAIL] ${svc}: ${status}" OK=false fi done fi echo "" if [ "$OK" = true ]; then echo "=== All services healthy! ===" exit 0 else echo "=== Some services are not healthy! ===" exit 1 fi