/
/
/
Ansible role that deployes services on my runner machine
1#!/bin/bash
2# Runner Services Log Viewer
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# Available services
15SERVICES=(
16{% if frigate_enabled %}
17 "frigate:{{ frigate_config_dir }}"
18{% endif %}
19{% if immich_enabled %}
20 "immich:{{ immich_config_dir }}"
21{% endif %}
22{% if forgejo_enabled %}
23 "forgejo:{{ forgejo_config_dir }}"
24{% endif %}
25{% if web_tools_enabled %}
26 "web-tools:{{ web_tools_config_dir }}"
27{% endif %}
28{% if tandoor_enabled %}
29 "tandoor:{{ tandoor_config_dir }}"
30{% endif %}
31{% if macros_enabled %}
32 "macros:{{ macros_config_dir }}"
33{% endif %}
34{% if mealie_enabled %}
35 "mealie:{{ mealie_config_dir }}"
36{% endif %}
37{% if ghost_enabled %}
38 "ghost:{{ ghost_config_dir }}"
39{% endif %}
40)
41
42show_usage() {
43 echo -e "${BLUE}Runner Services Log Viewer${NC}"
44 echo ""
45 echo "Usage: $0 [service] [options]"
46 echo ""
47 echo "Available services:"
48{% if frigate_enabled %}
49 echo " frigate - CCTV system logs"
50{% endif %}
51{% if immich_enabled %}
52 echo " immich - Photo management logs"
53{% endif %}
54{% if forgejo_enabled %}
55 echo " forgejo - Git server logs"
56{% endif %}
57{% if web_tools_enabled %}
58 echo " web-tools - Web tools logs (Stirling-PDF, ConvertX, CyberChef, IT-Tools)"
59{% endif %}
60{% if tandoor_enabled %}
61 echo " tandoor - Recipe manager logs"
62{% endif %}
63{% if macros_enabled %}
64 echo " macros - Macro Checker logs"
65{% endif %}
66{% if mealie_enabled %}
67 echo " mealie - Mealie recipe manager logs"
68{% endif %}
69{% if ghost_enabled %}
70 echo " ghost - CMS logs"
71{% endif %}
72 echo " all - All services (default)"
73 echo ""
74 echo "Options:"
75 echo " -f, --follow Follow log output (like tail -f)"
76 echo " -n, --lines N Show last N lines (default: 100)"
77 echo " --since TIME Show logs since timestamp (e.g., '1h', '2023-01-01T00:00:00')"
78 echo " --help Show this help"
79 echo ""
80 echo "Examples:"
81 echo " $0 # Show last 100 lines from all services"
82 echo " $0 frigate -f # Follow Frigate logs"
83 echo " $0 immich -n 50 # Show last 50 lines from Immich"
84 echo " $0 ghost --since 1h # Show Ghost logs from last hour"
85 echo ""
86}
87
88# Parse arguments
89SERVICE=""
90FOLLOW=false
91LINES=100
92SINCE=""
93
94while [[ $# -gt 0 ]]; do
95 case $1 in
96 -h|--help)
97 show_usage
98 exit 0
99 ;;
100 -f|--follow)
101 FOLLOW=true
102 shift
103 ;;
104 -n|--lines)
105 LINES="$2"
106 shift 2
107 ;;
108 --since)
109 SINCE="$2"
110 shift 2
111 ;;
112 *)
113 if [[ -z "$SERVICE" ]]; then
114 SERVICE="$1"
115 else
116 echo -e "${RED}Error: Unknown argument '$1'${NC}"
117 show_usage
118 exit 1
119 fi
120 shift
121 ;;
122 esac
123done
124
125# Default to 'all' if no service specified
126if [[ -z "$SERVICE" ]]; then
127 SERVICE="all"
128fi
129
130view_service_logs() {
131 local service_name="$1"
132 local service_dir="$2"
133
134 if [[ ! -f "$service_dir/docker-compose.yml" ]]; then
135 echo -e "${RED}Error: $service_name not found at $service_dir${NC}"
136 return 1
137 fi
138
139 echo -e "${BLUE}=== $service_name logs ===${NC}"
140
141 cd "$service_dir"
142
143 # Build docker compose logs command
144 local cmd="docker compose logs --no-color --timestamps"
145
146 if [[ "$FOLLOW" == "true" ]]; then
147 cmd="$cmd --follow"
148 fi
149
150 if [[ -n "$SINCE" ]]; then
151 cmd="$cmd --since $SINCE"
152 else
153 cmd="$cmd --tail $LINES"
154 fi
155
156 # Execute command
157 eval "$cmd"
158
159 echo ""
160}
161
162# Main execution
163case "$SERVICE" in
164 all)
165 if [[ "$FOLLOW" == "true" ]]; then
166 echo -e "${YELLOW}Warning: Follow mode not supported for 'all' services. Showing recent logs only.${NC}"
167 echo ""
168 fi
169
170 for service_info in "${SERVICES[@]}"; do
171 IFS=':' read -r service_name service_dir <<< "$service_info"
172 view_service_logs "$service_name" "$service_dir" || continue
173 done
174 ;;
175{% if frigate_enabled %}
176 frigate)
177 view_service_logs "frigate" "{{ frigate_config_dir }}"
178 ;;
179{% endif %}
180{% if immich_enabled %}
181 immich)
182 view_service_logs "immich" "{{ immich_config_dir }}"
183 ;;
184{% endif %}
185{% if forgejo_enabled %}
186 forgejo)
187 view_service_logs "forgejo" "{{ forgejo_config_dir }}"
188 ;;
189{% endif %}
190{% if web_tools_enabled %}
191 web-tools)
192 view_service_logs "web-tools" "{{ web_tools_config_dir }}"
193 ;;
194{% endif %}
195{% if tandoor_enabled %}
196 tandoor)
197 view_service_logs "tandoor" "{{ tandoor_config_dir }}"
198 ;;
199{% endif %}
200{% if macros_enabled %}
201 macros)
202 view_service_logs "macros" "{{ macros_config_dir }}"
203 ;;
204{% endif %}
205{% if mealie_enabled %}
206 mealie)
207 view_service_logs "mealie" "{{ mealie_config_dir }}"
208 ;;
209{% endif %}
210{% if ghost_enabled %}
211 ghost)
212 view_service_logs "ghost" "{{ ghost_config_dir }}"
213 ;;
214{% endif %}
215 *)
216 echo -e "${RED}Error: Unknown service '$SERVICE'${NC}"
217 echo ""
218 show_usage
219 exit 1
220 ;;
221esac