/
/
/
Ansible role that provisions my storage server.
1#!/bin/bash
2# Storage Services Log Viewer
3# Auto-generated by Ansible Storage 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 jellyfin_enabled %}
17 "jellyfin:{{ jellyfin_data_dir }}"
18{% endif %}
19{% if arr_stack_enabled %}
20 "arr-stack:{{ arr_config_dir }}"
21{% endif %}
22{% if calibre_enabled %}
23 "calibre-stack:{{ calibre_config_dir }}"
24{% endif %}
25{% if restic_backup_server_enabled %}
26 "restic-server:{{ restic_backup_config_dir }}"
27{% endif %}
28)
29
30show_usage() {
31 echo -e "${BLUE}Storage Services Log Viewer${NC}"
32 echo ""
33 echo "Usage: $0 [service] [options]"
34 echo ""
35 echo "Available services:"
36{% if jellyfin_enabled %}
37 echo " jellyfin - Media server logs"
38{% endif %}
39{% if arr_stack_enabled %}
40 echo " arr-stack - Media automation logs (Sonarr/Radarr/Prowlarr/Readarr)"
41{% endif %}
42{% if calibre_enabled %}
43 echo " calibre-stack - Ebook management logs (Calibre + Calibre-Web)"
44{% endif %}
45{% if restic_backup_server_enabled %}
46 echo " restic-server - Backup server logs"
47{% endif %}
48 echo " all - All services (default)"
49 echo ""
50 echo "Options:"
51 echo " -f, --follow Follow log output (like tail -f)"
52 echo " -n, --lines N Show last N lines (default: 100)"
53 echo " --since TIME Show logs since timestamp (e.g., '1h', '2023-01-01T00:00:00')"
54 echo " --help Show this help"
55 echo ""
56 echo "Examples:"
57 echo " $0 # Show last 100 lines from all services"
58 echo " $0 jellyfin -f # Follow Jellyfin logs"
59 echo " $0 arr-stack -n 50 # Show last 50 lines from Arr Stack"
60 echo " $0 calibre --since 1h # Show Calibre logs from last hour"
61 echo ""
62}
63
64# Parse arguments
65SERVICE=""
66FOLLOW=false
67LINES=100
68SINCE=""
69
70while [[ $# -gt 0 ]]; do
71 case $1 in
72 -h|--help)
73 show_usage
74 exit 0
75 ;;
76 -f|--follow)
77 FOLLOW=true
78 shift
79 ;;
80 -n|--lines)
81 LINES="$2"
82 shift 2
83 ;;
84 --since)
85 SINCE="$2"
86 shift 2
87 ;;
88 *)
89 if [[ -z "$SERVICE" ]]; then
90 SERVICE="$1"
91 else
92 echo -e "${RED}Error: Unknown argument '$1'${NC}"
93 show_usage
94 exit 1
95 fi
96 shift
97 ;;
98 esac
99done
100
101# Default to 'all' if no service specified
102if [[ -z "$SERVICE" ]]; then
103 SERVICE="all"
104fi
105
106view_service_logs() {
107 local service_name="$1"
108 local service_dir="$2"
109
110 if [[ ! -f "$service_dir/docker-compose.yml" ]]; then
111 echo -e "${RED}Error: $service_name not found at $service_dir${NC}"
112 return 1
113 fi
114
115 echo -e "${BLUE}=== $service_name logs ===${NC}"
116
117 cd "$service_dir"
118
119 # Build docker compose logs command
120 local cmd="docker compose logs --no-color --timestamps"
121
122 if [[ "$FOLLOW" == "true" ]]; then
123 cmd="$cmd --follow"
124 fi
125
126 if [[ -n "$SINCE" ]]; then
127 cmd="$cmd --since $SINCE"
128 else
129 cmd="$cmd --tail $LINES"
130 fi
131
132 # Execute command
133 eval "$cmd"
134
135 echo ""
136}
137
138# Main execution
139case "$SERVICE" in
140 all)
141 if [[ "$FOLLOW" == "true" ]]; then
142 echo -e "${YELLOW}Warning: Follow mode not supported for 'all' services. Showing recent logs only.${NC}"
143 echo ""
144 fi
145
146 for service_info in "${SERVICES[@]}"; do
147 IFS=':' read -r service_name service_dir <<< "$service_info"
148 view_service_logs "$service_name" "$service_dir" || continue
149 done
150 ;;
151{% if jellyfin_enabled %}
152 jellyfin)
153 view_service_logs "jellyfin" "{{ jellyfin_data_dir }}"
154 ;;
155{% endif %}
156{% if arr_stack_enabled %}
157 arr-stack)
158 view_service_logs "arr-stack" "{{ arr_config_dir }}"
159 ;;
160{% endif %}
161{% if calibre_enabled %}
162 calibre-stack)
163 view_service_logs "calibre-stack" "{{ calibre_config_dir }}"
164 ;;
165{% endif %}
166{% if restic_backup_server_enabled %}
167 restic-server)
168 view_service_logs "restic-server" "{{ restic_backup_config_dir }}"
169 ;;
170{% endif %}
171 *)
172 echo -e "${RED}Error: Unknown service '$SERVICE'${NC}"
173 echo ""
174 show_usage
175 exit 1
176 ;;
177esac