/
/
/
Ansible role that deployes services on my runner machine
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 web_tools_enabled %}
27 "web-tools:{{ web_tools_stirling_port }}:{{ web_tools_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 macros_enabled %}
33 "macros:{{ macros_port }}:{{ macros_config_dir }}/docker-compose.yml"
34{% endif %}
35{% if mealie_enabled %}
36 "mealie:{{ mealie_port }}:{{ mealie_config_dir }}/docker-compose.yml"
37{% endif %}
38{% if ghost_enabled %}
39 "ghost:{{ ghost_port }}:{{ ghost_config_dir }}/docker-compose.yml"
40{% endif %}
41)
42
43NFS_MOUNTS=(
44{% for mount in runner_nfs_mounts %}
45 "{{ mount.name }}:{{ mount.local_path }}"
46{% endfor %}
47)
48
49echo -e "${BLUE}===========================================${NC}"
50echo -e "${BLUE} RUNNER SERVICES STATUS CHECK ${NC}"
51echo -e "${BLUE}===========================================${NC}"
52echo ""
53
54# Check Docker daemon
55echo -e "${BLUE}Docker Status:${NC}"
56if systemctl is-active --quiet docker; then
57 echo -e " Docker daemon: ${GREEN}RUNNING${NC}"
58else
59 echo -e " Docker daemon: ${RED}STOPPED${NC}"
60 exit 1
61fi
62
63# Check Docker network
64if docker network inspect {{ runner_docker_network }} >/dev/null 2>&1; then
65 echo -e " Docker network: ${GREEN}EXISTS${NC} ({{ runner_docker_network }})"
66else
67 echo -e " Docker network: ${RED}MISSING${NC} ({{ runner_docker_network }})"
68fi
69echo ""
70
71# Check NFS mounts
72echo -e "${BLUE}NFS Mounts:${NC}"
73for mount_info in "${NFS_MOUNTS[@]}"; do
74 IFS=':' read -r mount_name mount_path <<< "$mount_info"
75 if mountpoint -q "$mount_path" 2>/dev/null; then
76 echo -e " $mount_name: ${GREEN}MOUNTED${NC} ($mount_path)"
77 else
78 echo -e " $mount_name: ${RED}NOT MOUNTED${NC} ($mount_path)"
79 fi
80done
81echo ""
82
83# Check service containers and ports
84echo -e "${BLUE}Services:${NC}"
85for service_info in "${SERVICES[@]}"; do
86 IFS=':' read -r service_name service_port compose_file <<< "$service_info"
87
88 # Check if compose file exists
89 if [[ ! -f "$compose_file" ]]; then
90 echo -e " $service_name: ${RED}NO CONFIG${NC} ($compose_file missing)"
91 continue
92 fi
93
94 # Check container status
95 container_status="UNKNOWN"
96 if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
97 if cd "$(dirname "$compose_file")" && docker compose ps -q | grep -q .; then
98 if cd "$(dirname "$compose_file")" && docker compose ps | grep -q "Up"; then
99 container_status="${GREEN}RUNNING${NC}"
100 else
101 container_status="${RED}STOPPED${NC}"
102 fi
103 else
104 container_status="${RED}NOT FOUND${NC}"
105 fi
106 fi
107
108 # Check port accessibility
109 port_status="${RED}CLOSED${NC}"
110 if timeout 3 bash -c "echo >/dev/tcp/localhost/$service_port" 2>/dev/null; then
111 port_status="${GREEN}OPEN${NC}"
112 fi
113
114 echo -e " $service_name: Container $container_status | Port $service_port $port_status"
115done
116echo ""
117
118# Check disk usage
119echo -e "${BLUE}Storage Usage:${NC}"
120echo -e " Service directories: $(du -sh /docker/* 2>/dev/null | awk '{total+=$1}END{print total"K"}')"
121echo -e " Individual services:"
122{% if frigate_enabled %}
123echo -e " Frigate: $(du -sh {{ frigate_config_dir }} 2>/dev/null | cut -f1) ({{ frigate_config_dir }})"
124{% endif %}
125{% if immich_enabled %}
126echo -e " Immich: $(du -sh {{ immich_config_dir }} 2>/dev/null | cut -f1) ({{ immich_config_dir }})"
127{% endif %}
128{% if forgejo_enabled %}
129echo -e " Forgejo: $(du -sh {{ forgejo_config_dir }} 2>/dev/null | cut -f1) ({{ forgejo_config_dir }})"
130{% endif %}
131{% if web_tools_enabled %}
132echo -e " Web Tools: $(du -sh {{ web_tools_config_dir }} 2>/dev/null | cut -f1) ({{ web_tools_config_dir }})"
133{% endif %}
134{% if mealie_enabled %}
135echo -e " Mealie: $(du -sh {{ mealie_config_dir }} 2>/dev/null | cut -f1) ({{ mealie_config_dir }})"
136{% endif %}
137{% if macros_enabled %}
138echo -e " Macro Checker: $(du -sh {{ macros_config_dir }} 2>/dev/null | cut -f1) ({{ macros_config_dir }})"
139{% endif %}
140{% if tandoor_enabled %}
141echo -e " Tandoor: $(du -sh {{ tandoor_config_dir }} 2>/dev/null | cut -f1) ({{ tandoor_config_dir }})"
142{% endif %}
143{% if ghost_enabled %}
144echo -e " Ghost: $(du -sh {{ ghost_config_dir }} 2>/dev/null | cut -f1) ({{ ghost_config_dir }})"
145{% endif %}
146echo ""
147
148# Check recent logs for errors
149echo -e "${BLUE}Recent Issues:${NC}"
150error_count=0
151for service_info in "${SERVICES[@]}"; do
152 IFS=':' read -r service_name service_port compose_file <<< "$service_info"
153 if [[ -f "$compose_file" ]]; then
154 cd "$(dirname "$compose_file")"
155 if errors=$(docker compose logs --tail=10 2>/dev/null | grep -i "error\|failed\|exception" | wc -l); then
156 if [[ $errors -gt 0 ]]; then
157 echo -e " $service_name: ${YELLOW}$errors errors${NC} in recent logs"
158 ((error_count++))
159 fi
160 fi
161 fi
162done
163
164if [[ $error_count -eq 0 ]]; then
165 echo -e " ${GREEN}No recent errors detected${NC}"
166fi
167echo ""
168
169# System resource usage
170echo -e "${BLUE}System Resources:${NC}"
171echo -e " CPU Usage: $(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1)%"
172echo -e " Memory Usage: $(free | grep Mem | awk '{printf("%.1f%%", $3/$2 * 100.0)}')"
173echo -e " Disk Usage (root): $(df -h / | awk 'NR==2{printf "%s", $5}')"
174echo ""
175
176echo -e "${BLUE}===========================================${NC}"
177echo -e "${BLUE}Status check completed at $(date)${NC}"
178echo -e "${BLUE}===========================================${NC}"
179
180# Exit codes for automation
181# 0: All services healthy
182# 1: Critical issues (Docker down, etc.)
183# 2: Some services have issues but system functional
184exit_code=0
185for service_info in "${SERVICES[@]}"; do
186 IFS=':' read -r service_name service_port compose_file <<< "$service_info"
187 if ! timeout 3 bash -c "echo >/dev/tcp/localhost/$service_port" 2>/dev/null; then
188 exit_code=2
189 fi
190done
191
192exit $exit_code