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