#!/bin/bash # Service health check script for Arrs Media Stack # Generated by Ansible set -e COMPOSE_DIR="{{ docker_compose_dir }}" SERVICES=("sonarr" "radarr" "lidarr" "bazarr" "prowlarr" "watchtower") PORTS=({{ ports.sonarr }} {{ ports.radarr }} {{ ports.lidarr }} {{ ports.bazarr }} {{ ports.prowlarr }}) # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' echo "=== Arrs Media Stack Health Check ===" echo "Timestamp: $(date)" echo # Check if compose directory exists if [[ ! -d "$COMPOSE_DIR" ]]; then echo -e "${RED}ERROR: Compose directory not found: $COMPOSE_DIR${NC}" exit 1 fi cd "$COMPOSE_DIR" # Check Docker Compose services echo "Docker Compose Services:" docker-compose ps echo echo "Service Health Status:" # Check each service for i in "${!SERVICES[@]}"; do service="${SERVICES[$i]}" # Skip watchtower port check if [[ "$service" == "watchtower" ]]; then if docker-compose ps "$service" | grep -q "Up"; then echo -e " ${service}: ${GREEN}Running${NC}" else echo -e " ${service}: ${RED}Not Running${NC}" fi continue fi port="${PORTS[$i]}" # Check if container is running if docker-compose ps "$service" | grep -q "Up"; then # Check if port is responding if curl -s -f "http://localhost:$port/ping" >/dev/null 2>&1 || \ curl -s -f "http://localhost:$port" >/dev/null 2>&1 || \ nc -z localhost "$port" 2>/dev/null; then echo -e " ${service} (port $port): ${GREEN}Healthy${NC}" else echo -e " ${service} (port $port): ${YELLOW}Running but not responding${NC}" fi else echo -e " ${service} (port $port): ${RED}Not Running${NC}" fi done echo echo "System Resources:" echo " Memory: $(free -h | grep Mem | awk '{print $3 "/" $2}')" echo " Disk: $(df -h {{ docker_root }} | tail -1 | awk '{print $3 "/" $2 " (" $5 ")"}')" echo echo "Recent Container Events:" docker events --since="1h" --until="now" 2>/dev/null | tail -5 || echo " No recent events" echo echo "=== End Health Check ==="