/
/
/
1#!/bin/bash
2# Runner Services Status Check
3# Auto-generated by Ansible Runner Role
4
5set -euo pipefail
6
7# Colors for output
8RED='\033[0;31m'
9GREEN='\033[0;32m'
10YELLOW='\033[1;33m'
11BLUE='\033[0;34m'
12NC='\033[0m' # No Color
13
14# Configuration
15# Using consolidated /docker/[service] structure
16SERVICES=(
17{% if frigate_enabled %}
18 "frigate:{{ frigate_port }}:{{ frigate_config_dir }}/docker-compose.yml"
19{% endif %}
20{% if immich_enabled %}
21 "immich:{{ immich_server_port }}:{{ immich_config_dir }}/docker-compose.yml"
22{% endif %}
23{% if forgejo_enabled %}
24 "forgejo:{{ forgejo_http_port }}:{{ forgejo_config_dir }}/docker-compose.yml"
25{% endif %}
26{% if stirling_pdf_enabled %}
27 "stirling-pdf:{{ stirling_pdf_port }}:{{ stirling_pdf_config_dir }}/docker-compose.yml"
28{% endif %}
29{% if tandoor_enabled %}
30 "tandoor:{{ tandoor_port }}:{{ tandoor_config_dir }}/docker-compose.yml"
31{% endif %}
32{% if ghost_enabled %}
33 "ghost:{{ ghost_port }}:{{ ghost_config_dir }}/docker-compose.yml"
34{% endif %}
35)
36
37NFS_MOUNTS=(
38{% for mount in runner_nfs_mounts %}
39 "{{ mount.name }}:{{ mount.local_path }}"
40{% endfor %}
41)
42
43echo -e "${BLUE}===========================================${NC}"
44echo -e "${BLUE} RUNNER SERVICES STATUS CHECK ${NC}"
45echo -e "${BLUE}===========================================${NC}"
46echo ""
47
48# Check Docker daemon
49echo -e "${BLUE}Docker Status:${NC}"
50if systemctl is-active --quiet docker; then
51 echo -e " Docker daemon: ${GREEN}RUNNING${NC}"
52else
53 echo -e " Docker daemon: ${RED}STOPPED${NC}"
54 exit 1
55fi
56
57# Check Docker network
58if docker network inspect {{ runner_docker_network }} >/dev/null 2>&1; then
59 echo -e " Docker network: ${GREEN}EXISTS${NC} ({{ runner_docker_network }})"
60else
61 echo -e " Docker network: ${RED}MISSING${NC} ({{ runner_docker_network }})"
62fi
63echo ""
64
65# Check NFS mounts
66echo -e "${BLUE}NFS Mounts:${NC}"
67for mount_info in "${NFS_MOUNTS[@]}"; do
68 IFS=':' read -r mount_name mount_path <<< "$mount_info"
69 if mountpoint -q "$mount_path" 2>/dev/null; then
70 echo -e " $mount_name: ${GREEN}MOUNTED${NC} ($mount_path)"
71 else
72 echo -e " $mount_name: ${RED}NOT MOUNTED${NC} ($mount_path)"
73 fi
74done
75echo ""
76
77# Check service containers and ports
78echo -e "${BLUE}Services:${NC}"
79for service_info in "${SERVICES[@]}"; do
80 IFS=':' read -r service_name service_port compose_file <<< "$service_info"
81
82 # Check if compose file exists
83 if [[ ! -f "$compose_file" ]]; then
84 echo -e " $service_name: ${RED}NO CONFIG${NC} ($compose_file missing)"
85 continue
86 fi
87
88 # Check container status
89 container_status="UNKNOWN"
90 if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
91 if cd "$(dirname "$compose_file")" && docker compose ps -q | grep -q .; then
92 if cd "$(dirname "$compose_file")" && docker compose ps | grep -q "Up"; then
93 container_status="${GREEN}RUNNING${NC}"
94 else
95 container_status="${RED}STOPPED${NC}"
96 fi
97 else
98 container_status="${RED}NOT FOUND${NC}"
99 fi
100 fi
101
102 # Check port accessibility
103 port_status="${RED}CLOSED${NC}"
104 if timeout 3 bash -c "echo >/dev/tcp/localhost/$service_port" 2>/dev/null; then
105 port_status="${GREEN}OPEN${NC}"
106 fi
107
108 echo -e " $service_name: Container $container_status | Port $service_port $port_status"
109done
110echo ""
111
112# Check disk usage
113echo -e "${BLUE}Storage Usage:${NC}"
114echo -e " Service directories: $(du -sh /docker/* 2>/dev/null | awk '{total+=$1}END{print total"K"}')"
115echo -e " Individual services:"
116{% if frigate_enabled %}
117echo -e " Frigate: $(du -sh {{ frigate_config_dir }} 2>/dev/null | cut -f1) ({{ frigate_config_dir }})"
118{% endif %}
119{% if immich_enabled %}
120echo -e " Immich: $(du -sh {{ immich_config_dir }} 2>/dev/null | cut -f1) ({{ immich_config_dir }})"
121{% endif %}
122{% if forgejo_enabled %}
123echo -e " Forgejo: $(du -sh {{ forgejo_config_dir }} 2>/dev/null | cut -f1) ({{ forgejo_config_dir }})"
124{% endif %}
125{% if stirling_pdf_enabled %}
126echo -e " Stirling-PDF: $(du -sh {{ stirling_pdf_config_dir }} 2>/dev/null | cut -f1) ({{ stirling_pdf_config_dir }})"
127{% endif %}
128{% if tandoor_enabled %}
129echo -e " Tandoor: $(du -sh {{ tandoor_config_dir }} 2>/dev/null | cut -f1) ({{ tandoor_config_dir }})"
130{% endif %}
131{% if ghost_enabled %}
132echo -e " Ghost: $(du -sh {{ ghost_config_dir }} 2>/dev/null | cut -f1) ({{ ghost_config_dir }})"
133{% endif %}
134echo ""
135
136# Check recent logs for errors
137echo -e "${BLUE}Recent Issues:${NC}"
138error_count=0
139for service_info in "${SERVICES[@]}"; do
140 IFS=':' read -r service_name service_port compose_file <<< "$service_info"
141 if [[ -f "$compose_file" ]]; then
142 cd "$(dirname "$compose_file")"
143 if errors=$(docker compose logs --tail=10 2>/dev/null | grep -i "error\|failed\|exception" | wc -l); then
144 if [[ $errors -gt 0 ]]; then
145 echo -e " $service_name: ${YELLOW}$errors errors${NC} in recent logs"
146 ((error_count++))
147 fi
148 fi
149 fi
150done
151
152if [[ $error_count -eq 0 ]]; then
153 echo -e " ${GREEN}No recent errors detected${NC}"
154fi
155echo ""
156
157# System resource usage
158echo -e "${BLUE}System Resources:${NC}"
159echo -e " CPU Usage: $(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1)%"
160echo -e " Memory Usage: $(free | grep Mem | awk '{printf("%.1f%%", $3/$2 * 100.0)}')"
161echo -e " Disk Usage (root): $(df -h / | awk 'NR==2{printf "%s", $5}')"
162echo ""
163
164echo -e "${BLUE}===========================================${NC}"
165echo -e "${BLUE}Status check completed at $(date)${NC}"
166echo -e "${BLUE}===========================================${NC}"
167
168# Exit codes for automation
169# 0: All services healthy
170# 1: Critical issues (Docker down, etc.)
171# 2: Some services have issues but system functional
172exit_code=0
173for service_info in "${SERVICES[@]}"; do
174 IFS=':' read -r service_name service_port compose_file <<< "$service_info"
175 if ! timeout 3 bash -c "echo >/dev/tcp/localhost/$service_port" 2>/dev/null; then
176 exit_code=2
177 fi
178done
179
180exit $exit_code