All state/data file paths in scripts and PHP now resolve via STATE_DIR / DATA_DIR / PERSISTENT_CONF_CACHE instead of hardcoded /boot/config/ or /tmp/ paths, so the ecosystem works in both internal and appdata storage modes. PHP layer (watchdog.php, partnership.php, fallback.php, monitor.php, snapshot.php, config.php): all state reads switched to STATE_DIR constant; remote state reads use the new vv_remote_state_cmd() helper which resolves the remote's SCRIPTS_DIR via their varaverk.cfg before building the path. conf_sync.sh: fixed SCRIPTS_ROOT → SCRIPTS_DIR bug on MY_CONF path; added _remote_scripts_dir() to resolve partner's SCRIPTS_DIR before SCP pull. fallback.php page: added controls card (PARTNERSHIP_ENABLED, FALLBACK_ENABLED, FALLBACK_RSYNC_ENABLED toggles), status grid, and settings card. README and Manual updated for System_Essentials, Watchdogs, Fallback, Rsync, Media, Monitors, Orchestrators, Partnership: added new scripts (conf_sync, conf_cache_save/restore, conf_cache_watchdog, play_state_sync, start_webhook_listener, upgrade_webhook_handler), corrected all stale /boot/config/ state file paths to $STATE_DIR/$DATA_DIR, noted webgui/php_fpm/mover/user_scripts scripts moved to Plugin/unraid/System_Essentials, fixed start_webhook_listener.sh header (Node.js, not PHP -S).
71 lines
2.6 KiB
Bash
Executable File
71 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# ==============================================================================================
|
|
# ============================= Conf Cache Watchdog ============================================
|
|
# ==============================================================================================
|
|
#
|
|
# PURPOSE
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
# Maintains the persistent partner conf backup at $PERSISTENT_CONF_CACHE.
|
|
# Runs every 15 minutes 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
|
|
require_partnership
|
|
|
|
[[ "${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="$PERSISTENT_CONF_CACHE"
|
|
|
|
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
|