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).
79 lines
2.7 KiB
Bash
Executable File
79 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# ==============================================================================================
|
|
# ============================= Conf Cache Restore =============================================
|
|
# ==============================================================================================
|
|
#
|
|
# PURPOSE
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
# Runs at array start after conf_sync.sh. Checks whether partner confs made it
|
|
# into the RAM cache. If any are missing (partner was unreachable at boot) and
|
|
# a persistent backup exists from the previous shutdown, loads the missing confs
|
|
# from backup into the RAM cache so scripts like fallback.sh have partner vars.
|
|
#
|
|
# Always removes the persistent backup when done — used or not.
|
|
#
|
|
# Normal reboot (partner up):
|
|
# conf_sync.sh pulls fresh → RAM cache complete → backup not needed → removed
|
|
#
|
|
# Edge case (partner down at boot):
|
|
# conf_sync.sh fails to pull → RAM cache missing partner → backup loaded into
|
|
# RAM → backup removed → fallback.sh runs with last-known-good partner vars
|
|
#
|
|
# Own conf is never in the backup — it's always on disk.
|
|
# ==============================================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/../load_config.sh"
|
|
|
|
parse_args "$@"
|
|
detect_hosts
|
|
require_partnership
|
|
|
|
RAM_CACHE="/tmp/.cache/vv/d"
|
|
SAVE_DIR="$PERSISTENT_CONF_CACHE"
|
|
|
|
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made"
|
|
|
|
if [[ ! -d "$SAVE_DIR" ]]; then
|
|
log "No persistent conf backup found — nothing to restore"
|
|
exit 0
|
|
fi
|
|
|
|
restored=0
|
|
for conf in "$SAVE_DIR"/host*.conf; do
|
|
[[ -f "$conf" ]] || continue
|
|
base="$(basename "$conf")"
|
|
[[ "${base,,}" == "${MY_ID,,}.conf" ]] && continue
|
|
|
|
if [[ -f "$RAM_CACHE/$base" ]]; then
|
|
log "$base already in RAM cache (conf_sync succeeded) — skipping"
|
|
continue
|
|
fi
|
|
|
|
if [[ "$DRY_RUN" == true ]]; then
|
|
warn "DRY RUN — would restore $base → RAM cache"
|
|
(( restored++ ))
|
|
continue
|
|
fi
|
|
|
|
mkdir -p "$RAM_CACHE"
|
|
if cp "$conf" "$RAM_CACHE/$base"; then
|
|
echo "Restored $base from persistent backup → RAM cache ✅"
|
|
(( restored++ ))
|
|
else
|
|
warn "Failed to restore $base"
|
|
fi
|
|
done
|
|
|
|
[[ "$restored" -gt 0 ]] && \
|
|
warn "Loaded $restored partner conf(s) from persistent backup — partner was unreachable at array start"
|
|
|
|
if [[ "$DRY_RUN" == false ]]; then
|
|
rm -rf "$SAVE_DIR"
|
|
log "Persistent conf backup cleared"
|
|
else
|
|
warn "DRY RUN — would remove $SAVE_DIR"
|
|
fi
|
|
|
|
exit 0
|