diff --git a/Configurations/master.conf b/Configurations/master.conf index 2ace255..8271391 100644 --- a/Configurations/master.conf +++ b/Configurations/master.conf @@ -338,9 +338,10 @@ # system_watchdog.sh runs SYSTEM_WATCHDOG_SCRIPTS sequentially each cycle. # Called by watchdog_orchestrator.sh — not scheduled directly. SYSTEM_WATCHDOG_SCRIPTS=( - "Watchdogs/System/storage_watchdog.sh" # pool growth + runaway log detection + "Watchdogs/System/storage_watchdog.sh" # pool growth + runaway log detection "Plugin/unraid/Watchdogs/System/webgui_watchdog.sh" # WebGUI availability — nginx → php-fpm → emhttp - "Watchdogs/System/network_watchdog.sh" # internet, DDNS, Tailscale, NPM proxy + "Watchdogs/System/network_watchdog.sh" # internet, DDNS, Tailscale, NPM proxy + "Watchdogs/System/conf_cache_watchdog.sh" # maintain persistent conf backup while partner is offline ) # ━━━ Critical Sync Maintenance ━━━ diff --git a/Deployment/master.conf.template b/Deployment/master.conf.template index d7176d0..e2ffa66 100644 --- a/Deployment/master.conf.template +++ b/Deployment/master.conf.template @@ -333,9 +333,10 @@ # system_watchdog.sh runs SYSTEM_WATCHDOG_SCRIPTS sequentially each cycle. # Called by watchdog_orchestrator.sh — not scheduled directly. SYSTEM_WATCHDOG_SCRIPTS=( - "Watchdogs/System/storage_watchdog.sh" # pool growth + runaway log detection - "Watchdogs/System/webgui_watchdog.sh" # WebGUI availability — nginx → php-fpm → emhttp - "Watchdogs/System/network_watchdog.sh" # internet, DDNS, Tailscale, NPM proxy + "Watchdogs/System/storage_watchdog.sh" # pool growth + runaway log detection + "Watchdogs/System/webgui_watchdog.sh" # WebGUI availability — nginx → php-fpm → emhttp + "Watchdogs/System/network_watchdog.sh" # internet, DDNS, Tailscale, NPM proxy + "Watchdogs/System/conf_cache_watchdog.sh" # maintain persistent conf backup while partner is offline ) # ━━━ Critical Sync Maintenance ━━━ diff --git a/Watchdogs/System/conf_cache_watchdog.sh b/Watchdogs/System/conf_cache_watchdog.sh new file mode 100644 index 0000000..f553587 --- /dev/null +++ b/Watchdogs/System/conf_cache_watchdog.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# ============================================================================================== +# ============================= Conf Cache Watchdog ============================================ +# ============================================================================================== +# +# PURPOSE +# ───────────────────────────────────────────────────────────────────────────── +# Maintains the persistent partner conf backup at /boot/config/.cache/vv/d/. +# Runs every minute via SYSTEM_WATCHDOG_SCRIPTS. +# +# When remote is OFFLINE: +# Writes/refreshes partner confs from RAM cache → persistent location. +# Means if this host reboots while remote is still down, conf_cache_restore.sh +# can load the partner vars into RAM so fallback.sh has what it needs. +# +# When remote is ONLINE: +# Removes the persistent backup if present — not needed, conf_sync.sh will +# pull fresh on next boot. +# +# Silent when remote is online and no backup exists (normal state). +# No-op when FALLBACK_ENABLED=false or CONF_SYNC_ENABLED=false. +# ============================================================================================== + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/../../load_config.sh" + +parse_args "$@" +detect_hosts + +[[ "${FALLBACK_ENABLED:-false}" != "true" ]] && exit 0 +[[ "${CONF_SYNC_ENABLED:-true}" != "true" ]] && exit 0 +[[ -z "${REMOTE_ID:-}" ]] && exit 0 + +RAM_CACHE="/tmp/.cache/vv/d" +SAVE_DIR="/boot/config/.cache/vv/d" + +if ping_remote; then + if [[ -d "$SAVE_DIR" ]]; then + [[ "$DRY_RUN" == true ]] && warn "DRY RUN — would remove $SAVE_DIR (remote back online)" && exit 0 + rm -rf "$SAVE_DIR" + log "Remote online — persistent conf backup removed" + fi + exit 0 +fi + +# Remote offline — write/refresh backup from RAM cache +if [[ ! -d "$RAM_CACHE" ]]; then + log "Remote offline but RAM cache not populated — nothing to back up" + exit 0 +fi + +saved=0 +for conf in "$RAM_CACHE"/host*.conf; do + [[ -f "$conf" ]] || continue + base="$(basename "$conf")" + [[ "${base,,}" == "${MY_ID,,}.conf" ]] && continue + + if [[ "$DRY_RUN" == true ]]; then + warn "DRY RUN — would write $base → $SAVE_DIR/" + (( saved++ )) + continue + fi + + mkdir -p "$SAVE_DIR" + cp "$conf" "$SAVE_DIR/$base" && (( saved++ )) +done + +[[ "$saved" -gt 0 ]] && log "Remote offline — partner conf backup refreshed ($saved file(s))" +exit 0