Every script now has the established header format: PURPOSE with ─────── separator, OPERATIONAL MODEL, DESIGN PRINCIPLES, OPERATIONAL SAFEGUARDS, CONFIGURATION, and RUNTIME MODES — structured with full ====== banner sections throughout. Orchestrators converted from compact ── inline format to full banners. Stale emby-fallback and dirty sync references removed from Plugin/user_script_plug-in.sh.
181 lines
7.5 KiB
Bash
Executable File
181 lines
7.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# ==============================================================================================
|
|
# ============================= Sunday Morning Coffee Report ===================================
|
|
# ==============================================================================================
|
|
#
|
|
# PURPOSE
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
# Weekly monitoring orchestrator — runs all Sunday monitor scripts in sequence.
|
|
# Designed to be read over coffee while the system is fully caught up from the
|
|
# 2:30am maintenance window.
|
|
# Schedule: 0 7 * * 0 (7am Sunday — after weekly_sync_maintenance.sh finishes)
|
|
#
|
|
# ==============================================================================================
|
|
# OPERATIONAL MODEL
|
|
# ==============================================================================================
|
|
#
|
|
# Runs COFFEE_REPORT_SCRIPTS from master.conf in order. Each script runs
|
|
# independently, produces its own output, and notifies on findings.
|
|
# All scripts receive --dry-run and --log flags from this orchestrator when set.
|
|
#
|
|
# HOST1 primary: runs all scripts.
|
|
# HOST2: limited to host-aware scripts only — each script handles its own host logic.
|
|
#
|
|
# ==============================================================================================
|
|
# DESIGN PRINCIPLES
|
|
# ==============================================================================================
|
|
#
|
|
# Independent, Isolated Scripts
|
|
# Each monitor script is fully self-contained — a failure in one does not
|
|
# prevent the others from running. The orchestrator logs the failure and
|
|
# continues to the next script.
|
|
#
|
|
# Runs After the Full Weekly Window
|
|
# Scheduled 4+ hours after weekly_sync_maintenance.sh — the system is fully
|
|
# synced and containers are back up before any monitoring reads run. Reports
|
|
# reflect the settled post-maintenance state.
|
|
#
|
|
# ==============================================================================================
|
|
# OPERATIONAL SAFEGUARDS
|
|
# ==============================================================================================
|
|
#
|
|
# detect_hosts() — MY_ID in banner and summary
|
|
# Non-fatal steps — a failed script is logged; remaining scripts still run
|
|
# Flag pass-through — --dry-run and --log forwarded to all child scripts
|
|
#
|
|
# ==============================================================================================
|
|
# CONFIGURATION
|
|
# ==============================================================================================
|
|
#
|
|
# master.conf
|
|
#
|
|
# COFFEE_REPORT_SCRIPTS — ordered list of monitor scripts to run
|
|
#
|
|
# ==============================================================================================
|
|
# RUNTIME MODES
|
|
# ==============================================================================================
|
|
#
|
|
# sunday_morning_coffee_report.sh
|
|
# Normal run.
|
|
#
|
|
# sunday_morning_coffee_report.sh --dry-run
|
|
# Preview without any writes or notifications.
|
|
#
|
|
# sunday_morning_coffee_report.sh --log
|
|
# Verbose per-script output.
|
|
#
|
|
# sunday_morning_coffee_report.sh --status
|
|
# Show configured scripts and exit.
|
|
#
|
|
# ==============================================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
source "$SCRIPT_DIR/../load_config.sh"
|
|
|
|
SCRIPTS_ROOT="$SCRIPT_DIR/.."
|
|
|
|
parse_args "$@"
|
|
detect_hosts
|
|
|
|
# ==============================================================================================
|
|
# ━━━ Helpers ━━━
|
|
# ==============================================================================================
|
|
JOB_PASS=()
|
|
JOB_FAIL=()
|
|
|
|
run_job() {
|
|
local script_entry="$1"
|
|
local extra_dry=""
|
|
local extra_log=""
|
|
[[ "$DRY_RUN" == true ]] && extra_dry="--dry-run"
|
|
[[ "$ENABLE_LOGGING" == true ]] && extra_log="--log"
|
|
|
|
read -r -a script_args <<< "$script_entry"
|
|
local script_path="$SCRIPTS_ROOT/${script_args[0]}"
|
|
local script_name
|
|
script_name=$(basename "${script_args[0]}")
|
|
local extra_args=("${script_args[@]:1}")
|
|
|
|
if [[ ! -f "$script_path" ]]; then
|
|
error "$script_name — not found at $script_path"
|
|
JOB_FAIL+=("$script_name")
|
|
return 1
|
|
fi
|
|
|
|
log "Running: $script_name ${extra_args[*]}"
|
|
if bash "$script_path" "${extra_args[@]}" $extra_dry $extra_log; then
|
|
echo "$script_name — done ✅"
|
|
JOB_PASS+=("$script_name")
|
|
else
|
|
error "$script_name — failed (exit $?)"
|
|
JOB_FAIL+=("$script_name")
|
|
fi
|
|
}
|
|
|
|
# ==============================================================================================
|
|
# ━━━ Status ━━━
|
|
# ==============================================================================================
|
|
if [[ "$SHOW_STATUS" == true ]]; then
|
|
echo "━━━ Sunday Morning Coffee Report — Status ━━━"
|
|
echo " Host: $MY_ID"
|
|
echo " Scripts:"
|
|
if [[ ${#COFFEE_REPORT_SCRIPTS[@]} -eq 0 ]]; then
|
|
echo " None configured (COFFEE_REPORT_SCRIPTS in master.conf)"
|
|
else
|
|
for entry in "${COFFEE_REPORT_SCRIPTS[@]}"; do
|
|
[[ -n "$entry" ]] && echo " ☕ ${entry##*/}"
|
|
done
|
|
fi
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
exit 0
|
|
fi
|
|
|
|
# ==============================================================================================
|
|
# ━━━ Main ━━━
|
|
# ==============================================================================================
|
|
_unraid_ver=$(platform_get_os_version 2>/dev/null || echo "unknown")
|
|
_uptime_s=$(awk '{print int($1)}' /proc/uptime 2>/dev/null || echo 0)
|
|
_container_count=$(docker ps -q 2>/dev/null | wc -l || echo 0)
|
|
_rootfs_pct=$(df / --output=pcent 2>/dev/null | tail -1 | tr -d ' %')
|
|
|
|
echo ""
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "☕ Sunday Morning Coffee Report — $MY_ID"
|
|
[[ "$DRY_RUN" == true ]] && echo " [DRY RUN]"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
log "$ICON_HOST Server: $MY_ID ($LOCAL_SERVER_NAME) — unRAID $_unraid_ver"
|
|
log "$ICON_TIME Uptime: $(format_duration $_uptime_s)"
|
|
log "$ICON_CONTAINERS Docker: $_container_count container(s) running"
|
|
log "$ICON_HEALTH Rootfs: ${_rootfs_pct:-?}% used"
|
|
log "$ICON_GEAR Scripts: ${#COFFEE_REPORT_SCRIPTS[@]} configured"
|
|
|
|
if [[ ${#COFFEE_REPORT_SCRIPTS[@]} -eq 0 ]]; then
|
|
warn "No scripts configured — add entries to COFFEE_REPORT_SCRIPTS in master.conf"
|
|
exit 0
|
|
fi
|
|
|
|
for script_entry in "${COFFEE_REPORT_SCRIPTS[@]}"; do
|
|
[[ -z "$script_entry" ]] && continue
|
|
echo ""
|
|
run_job "$script_entry"
|
|
done
|
|
|
|
# ==============================================================================================
|
|
# ━━━ Summary ━━━
|
|
# ==============================================================================================
|
|
echo ""
|
|
echo "━━━━━ ☕ COFFEE REPORT SUMMARY ━━━━━"
|
|
echo "🖥️ Host: $MY_ID"
|
|
echo "⏱️ Done: $(date '+%Y-%m-%d %H:%M:%S')"
|
|
|
|
if [[ ${#JOB_PASS[@]} -gt 0 ]]; then
|
|
echo "✅ Passed: ${JOB_PASS[*]}"
|
|
fi
|
|
if [[ ${#JOB_FAIL[@]} -gt 0 ]]; then
|
|
echo "❌ Failed: ${JOB_FAIL[*]}"
|
|
fi
|
|
|
|
[[ ${#JOB_FAIL[@]} -gt 0 ]] && exit 1
|
|
exit 0
|