Make PARTNERSHIP_ENABLED the authoritative gate for all cross-server operations

Adds require_partnership() to common.sh — exits cleanly when PARTNERSHIP_ENABLED=false.
Removes FALLBACK_PARTNERSHIP_REQUIRED toggle — partnership is now always required,
not optional. Cross-server scripts (rsync, conf sync, fallback, arr sync, play state,
backup verify) all call require_partnership after detect_hosts.
This commit is contained in:
Gmer4Lfe
2026-06-19 18:27:41 -04:00
parent 7a12c3eee6
commit 0564580605
13 changed files with 77 additions and 80 deletions
-2
View File
@@ -687,8 +687,6 @@
FALLBACK_STATE_FILE="$STATE_DIR/fallback_state.db" FALLBACK_STATE_FILE="$STATE_DIR/fallback_state.db"
FALLBACK_ENABLED=true # HOST2 back online FALLBACK_ENABLED=true # HOST2 back online
# false = suppresses "not running" warnings in status scripts # false = suppresses "not running" warnings in status scripts
FALLBACK_PARTNERSHIP_REQUIRED=true # gate fallback on an active partnership
# false = standalone mode, no partnership dependency
FALLBACK_PARTNERSHIP_SUSPEND_AFTER=120 # minutes without active partnership before suspending FALLBACK_PARTNERSHIP_SUSPEND_AFTER=120 # minutes without active partnership before suspending
# 0 = suspend immediately when partnership goes inactive # 0 = suspend immediately when partnership goes inactive
-2
View File
@@ -682,8 +682,6 @@
FALLBACK_STATE_FILE="$STATE_DIR/fallback_state.db" FALLBACK_STATE_FILE="$STATE_DIR/fallback_state.db"
FALLBACK_ENABLED=false # set true once both servers are configured and paired FALLBACK_ENABLED=false # set true once both servers are configured and paired
# false = suppresses "not running" warnings in status scripts # false = suppresses "not running" warnings in status scripts
FALLBACK_PARTNERSHIP_REQUIRED=true # gate fallback on an active partnership
# false = standalone mode, no partnership dependency
FALLBACK_PARTNERSHIP_SUSPEND_AFTER=120 # minutes without active partnership before suspending FALLBACK_PARTNERSHIP_SUSPEND_AFTER=120 # minutes without active partnership before suspending
# 0 = suspend immediately when partnership goes inactive # 0 = suspend immediately when partnership goes inactive
+62 -73
View File
@@ -116,12 +116,11 @@
# Exits if the host cannot be identified — prevents running on an unknown machine. # Exits if the host cannot be identified — prevents running on an unknown machine.
# #
# Partnership Gate # Partnership Gate
# When FALLBACK_PARTNERSHIP_REQUIRED=true, fallback is only permitted when the # Fallback is only permitted when the local partnership DB reports an active
# local partnership DB reports an active partnership. If partnership goes inactive, # partnership. If partnership goes inactive, a grace timer starts. After
# a grace timer starts. After FALLBACK_PARTNERSHIP_SUSPEND_AFTER minutes the loop # FALLBACK_PARTNERSHIP_SUSPEND_AFTER minutes the loop suspends: no new FALLBACK
# suspends: no new FALLBACK is entered, and any live fallback containers are # is entered, and any live fallback containers are stopped cleanly. Resumes
# stopped cleanly. Resumes automatically when partnership becomes active again. # automatically when partnership becomes active again.
# Set FALLBACK_PARTNERSHIP_REQUIRED=false to run fallback without a partnership.
# #
# Silent by Default # Silent by Default
# State transitions: warn() — always visible. Healthy routine cycles: log() # State transitions: warn() — always visible. Healthy routine cycles: log()
@@ -174,11 +173,6 @@
# FALLBACK_ENABLED # FALLBACK_ENABLED
# false = exit cleanly (e.g. remote server being rebuilt). (default: false) # false = exit cleanly (e.g. remote server being rebuilt). (default: false)
# #
# FALLBACK_PARTNERSHIP_REQUIRED
# true = fallback is gated on an active partnership — suspends when no active
# partner is found after FALLBACK_PARTNERSHIP_SUSPEND_AFTER minutes.
# false = fallback runs standalone regardless of partnership state. (default: true)
#
# FALLBACK_PARTNERSHIP_SUSPEND_AFTER # FALLBACK_PARTNERSHIP_SUSPEND_AFTER
# Minutes without an active partnership before fallback suspends itself. # Minutes without an active partnership before fallback suspends itself.
# Grace period: fallback continues normally during this window. # Grace period: fallback continues normally during this window.
@@ -290,6 +284,7 @@ if ! command -v docker &>/dev/null; then
fi fi
detect_hosts detect_hosts
require_partnership
resolve_remote_ip resolve_remote_ip
# Validate unRAID notify script — used throughout for state change notifications # Validate unRAID notify script — used throughout for state change notifications
@@ -301,7 +296,7 @@ DOCKER_TIMEOUT=15
SSH_TIMEOUT=10 SSH_TIMEOUT=10
CONTAINER_VERIFY_WAIT=5 # seconds after start before verifying container is up CONTAINER_VERIFY_WAIT=5 # seconds after start before verifying container is up
log "$ICON_GEAR Config: check-interval=${FALLBACK_CHECK_INTERVAL}s handback-strikes=${FALLBACK_HANDBACK_STRIKES} partnership-required=${FALLBACK_PARTNERSHIP_REQUIRED:-true} rsync-enabled=${FALLBACK_RSYNC_ENABLED:-true}" log "$ICON_GEAR Config: check-interval=${FALLBACK_CHECK_INTERVAL}s handback-strikes=${FALLBACK_HANDBACK_STRIKES} rsync-enabled=${FALLBACK_RSYNC_ENABLED:-true}"
log "$ICON_GEAR Timeouts: docker=${DOCKER_TIMEOUT}s ssh=${SSH_TIMEOUT}s verify-wait=${CONTAINER_VERIFY_WAIT}s" log "$ICON_GEAR Timeouts: docker=${DOCKER_TIMEOUT}s ssh=${SSH_TIMEOUT}s verify-wait=${CONTAINER_VERIFY_WAIT}s"
# ============================================================================================== # ==============================================================================================
@@ -627,19 +622,15 @@ if [[ "$SHOW_STATUS" == true ]]; then
echo "$ICON_GEAR Enabled: $FALLBACK_ENABLED" echo "$ICON_GEAR Enabled: $FALLBACK_ENABLED"
echo "$ICON_GEAR Dry Run: $DRY_RUN" echo "$ICON_GEAR Dry Run: $DRY_RUN"
if [[ "${FALLBACK_PARTNERSHIP_REQUIRED:-true}" == "true" ]]; then SUSPENDED=$(state_get partnership_suspended)
SUSPENDED=$(state_get partnership_suspended) PLOST=$(state_get partner_lost_at)
PLOST=$(state_get partner_lost_at) if [[ "$SUSPENDED" == "true" ]]; then
if [[ "$SUSPENDED" == "true" ]]; then echo "$ICON_GEAR Partnership: SUSPENDED (no active partnership)"
echo "$ICON_GEAR Partnership: SUSPENDED (no active partnership)" elif [[ -n "$PLOST" && "$PLOST" != "0" ]]; then
elif [[ -n "$PLOST" && "$PLOST" != "0" ]]; then PLOST_MIN=$(( ($(date +%s) - PLOST) / 60 ))
PLOST_MIN=$(( ($(date +%s) - PLOST) / 60 )) echo "$ICON_GEAR Partnership: GRACE (${PLOST_MIN}min / ${FALLBACK_PARTNERSHIP_SUSPEND_AFTER:-120}min until suspend)"
echo "$ICON_GEAR Partnership: GRACE (${PLOST_MIN}min / ${FALLBACK_PARTNERSHIP_SUSPEND_AFTER:-120}min until suspend)"
else
echo "$ICON_GEAR Partnership: ACTIVE"
fi
else else
echo "$ICON_GEAR Partnership: REQUIRED=false (standalone mode)" echo "$ICON_GEAR Partnership: ACTIVE"
fi fi
echo "━━━━━━━━━━━━━━━━━━━━━━━" echo "━━━━━━━━━━━━━━━━━━━━━━━"
@@ -862,57 +853,55 @@ while [[ "$FALLBACK_RUNNING" == true ]]; do
log "Remote: $REMOTE_UP | Internet: $INTERNET_UP | State: $CURRENT_STATE" log "Remote: $REMOTE_UP | Internet: $INTERNET_UP | State: $CURRENT_STATE"
# ── Partnership gate ────────────────────────────────────────────────────────────────────── # ── Partnership gate ──────────────────────────────────────────────────────────────────────
# When FALLBACK_PARTNERSHIP_REQUIRED=true, a fallback without an active partner is # ── Partnership Gate ──────────────────────────────────────────────────────────────────────
# meaningless — who are we covering for? The gate suspends the loop after a grace # A fallback without an active partner is meaningless — who are we covering for?
# period and aborts any live fallback containers. Clears automatically when partnership # The gate suspends the loop after a grace period and aborts any live fallback
# is restored. # containers. Clears automatically when partnership becomes active again.
if [[ "${FALLBACK_PARTNERSHIP_REQUIRED:-true}" == "true" ]]; then if check_partnership_active; then
if check_partnership_active; then # Partnership healthy — clear any accumulated grace state
# Partnership healthy — clear any accumulated grace state if [[ "$(state_get partnership_suspended)" == "true" ]]; then
if [[ "$(state_get partnership_suspended)" == "true" ]]; then warn "Active partnership restored — re-enabling fallback monitoring"
warn "Active partnership restored — re-enabling fallback monitoring" state_set partnership_suspended "false"
state_set partnership_suspended "false" state_set partner_lost_at "0"
state_set partner_lost_at "0" notify "Fallback re-enabled on $(hostname) — active partnership restored" \
notify "Fallback re-enabled on $(hostname) — active partnership restored" \ "Fallback" "normal"
"Fallback" "normal" elif [[ "$(state_get partner_lost_at)" != "0" ]]; then
elif [[ "$(state_get partner_lost_at)" != "0" ]]; then log "Partnership recovered within grace window — resetting timer"
log "Partnership recovered within grace window — resetting timer" state_set partner_lost_at "0"
state_set partner_lost_at "0" fi
else
PARTNER_LOST_AT=$(state_get partner_lost_at)
if [[ -z "$PARTNER_LOST_AT" || "$PARTNER_LOST_AT" == "0" ]]; then
warn "No active partnership detected — grace timer started (${FALLBACK_PARTNERSHIP_SUSPEND_AFTER:-120}min before suspend)"
state_set partner_lost_at "$NOW"
PARTNER_LOST_AT=$NOW
fi
PARTNER_LOST_MIN=$(( (NOW - PARTNER_LOST_AT) / 60 ))
SUSPEND_AFTER=${FALLBACK_PARTNERSHIP_SUSPEND_AFTER:-120}
if [[ "$(state_get partnership_suspended)" == "true" || "$PARTNER_LOST_MIN" -ge "$SUSPEND_AFTER" ]]; then
# Suspend — abort any live fallback containers, then skip this cycle entirely
if [[ "$(state_get partnership_suspended)" != "true" ]]; then
warn "No active partnership for ${PARTNER_LOST_MIN}min — suspending fallback"
state_set partnership_suspended "true"
notify "Fallback suspended on $(hostname) — no active partnership for ${PARTNER_LOST_MIN}min" \
"Fallback" "warning"
fi fi
if [[ "$CURRENT_STATE" == "FALLBACK" ]]; then
warn "Aborting in-progress fallback — partnership suspended"
_abort_fallback_containers
state_set state "NORMAL"
state_set fallback_start "0"
state_set handback_strikes "0"
notify "Fallback aborted on $(hostname) — no active partnership, containers stopped" \
"Fallback" "warning"
fi
log "Partnership suspended — skipping fallback cycle"
sleep "$FALLBACK_CHECK_INTERVAL" & wait $!
continue
else else
PARTNER_LOST_AT=$(state_get partner_lost_at) log "No active partnership — ${PARTNER_LOST_MIN}min elapsed / ${SUSPEND_AFTER}min until suspend"
if [[ -z "$PARTNER_LOST_AT" || "$PARTNER_LOST_AT" == "0" ]]; then
warn "No active partnership detected — grace timer started (${FALLBACK_PARTNERSHIP_SUSPEND_AFTER:-120}min before suspend)"
state_set partner_lost_at "$NOW"
PARTNER_LOST_AT=$NOW
fi
PARTNER_LOST_MIN=$(( (NOW - PARTNER_LOST_AT) / 60 ))
SUSPEND_AFTER=${FALLBACK_PARTNERSHIP_SUSPEND_AFTER:-120}
if [[ "$(state_get partnership_suspended)" == "true" || "$PARTNER_LOST_MIN" -ge "$SUSPEND_AFTER" ]]; then
# Suspend — abort any live fallback containers, then skip this cycle entirely
if [[ "$(state_get partnership_suspended)" != "true" ]]; then
warn "No active partnership for ${PARTNER_LOST_MIN}min — suspending fallback"
state_set partnership_suspended "true"
notify "Fallback suspended on $(hostname) — no active partnership for ${PARTNER_LOST_MIN}min" \
"Fallback" "warning"
fi
if [[ "$CURRENT_STATE" == "FALLBACK" ]]; then
warn "Aborting in-progress fallback — partnership suspended"
_abort_fallback_containers
state_set state "NORMAL"
state_set fallback_start "0"
state_set handback_strikes "0"
notify "Fallback aborted on $(hostname) — no active partnership, containers stopped" \
"Fallback" "warning"
fi
log "Partnership suspended — skipping fallback cycle"
sleep "$FALLBACK_CHECK_INTERVAL" & wait $!
continue
else
log "No active partnership — ${PARTNER_LOST_MIN}min elapsed / ${SUSPEND_AFTER}min until suspend"
fi
fi fi
fi fi
+1
View File
@@ -174,6 +174,7 @@ done
unset _tool unset _tool
detect_hosts detect_hosts
require_partnership
# ── Runtime config with defaults ────────────────────────────────────────────────────────────── # ── Runtime config with defaults ──────────────────────────────────────────────────────────────
ARR_SYNC_ENABLED="${ARR_SYNC_ENABLED:-true}" ARR_SYNC_ENABLED="${ARR_SYNC_ENABLED:-true}"
+1
View File
@@ -80,6 +80,7 @@ for _a in "$@"; do
[[ "$_a" == "--full" ]] && FULL_SYNC=true || _FILTERED+=("$_a") [[ "$_a" == "--full" ]] && FULL_SYNC=true || _FILTERED+=("$_a")
done done
parse_args "${_FILTERED[@]}" parse_args "${_FILTERED[@]}"
require_partnership
# ============================================================================================== # ==============================================================================================
# ━━━ Setup ━━━ # ━━━ Setup ━━━
+1
View File
@@ -124,6 +124,7 @@ acquire_lock
# detect_hosts() sets MY_ID and aliases BACKUP_VERIFY_SHARES + DAILY_SYNC_SHARES # detect_hosts() sets MY_ID and aliases BACKUP_VERIFY_SHARES + DAILY_SYNC_SHARES
detect_hosts detect_hosts
require_partnership
# Share selection — configured list or fallback to daily sync shares # Share selection — configured list or fallback to daily sync shares
if [[ ${#BACKUP_VERIFY_SHARES[@]} -gt 0 ]]; then if [[ ${#BACKUP_VERIFY_SHARES[@]} -gt 0 ]]; then
+1 -3
View File
@@ -56,14 +56,13 @@ function vv_fallback_state(): array {
$enabled = ($vars['FALLBACK_ENABLED'] ?? 'false') === 'true'; $enabled = ($vars['FALLBACK_ENABLED'] ?? 'false') === 'true';
$interval = (int)($vars['FALLBACK_CHECK_INTERVAL'] ?? 30); $interval = (int)($vars['FALLBACK_CHECK_INTERVAL'] ?? 30);
$reqStrikes = (int)($vars['FALLBACK_HANDBACK_STRIKES'] ?? 3); $reqStrikes = (int)($vars['FALLBACK_HANDBACK_STRIKES'] ?? 3);
$ptRequired = ($vars['FALLBACK_PARTNERSHIP_REQUIRED'] ?? 'true') === 'true';
$suspendAfter = (int)($vars['FALLBACK_PARTNERSHIP_SUSPEND_AFTER'] ?? 120); $suspendAfter = (int)($vars['FALLBACK_PARTNERSHIP_SUSPEND_AFTER'] ?? 120);
$stateFile = '/tmp/fallback_state.db'; $stateFile = '/tmp/fallback_state.db';
if (!file_exists($stateFile)) { if (!file_exists($stateFile)) {
return ['state' => 'UNKNOWN', 'enabled' => $enabled, 'check_interval' => $interval, return ['state' => 'UNKNOWN', 'enabled' => $enabled, 'check_interval' => $interval,
'handback_strikes' => 0, 'handback_strikes_required' => $reqStrikes, 'handback_strikes' => 0, 'handback_strikes_required' => $reqStrikes,
'partnership_required' => $ptRequired, 'partnership_suspended' => false, 'partnership_suspended' => false,
'partner_lost_at' => 0, 'partnership_suspend_after' => $suspendAfter]; 'partner_lost_at' => 0, 'partnership_suspend_after' => $suspendAfter];
} }
$raw = []; $raw = [];
@@ -83,7 +82,6 @@ function vv_fallback_state(): array {
'enabled' => $enabled, 'enabled' => $enabled,
'check_interval' => $interval, 'check_interval' => $interval,
'handback_strikes_required' => $reqStrikes, 'handback_strikes_required' => $reqStrikes,
'partnership_required' => $ptRequired,
'partnership_suspend_after' => $suspendAfter, 'partnership_suspend_after' => $suspendAfter,
]; ];
} }
+1
View File
@@ -186,6 +186,7 @@ fi
detect_hosts detect_hosts
require_partnership
# Tier 1 global gate — Tier 2 (per-orchestrator) checked by caller # Tier 1 global gate — Tier 2 (per-orchestrator) checked by caller
if ! check_rsync_enabled; then if ! check_rsync_enabled; then
+1
View File
@@ -27,6 +27,7 @@ source "$SCRIPT_DIR/../load_config.sh"
parse_args "$@" parse_args "$@"
detect_hosts detect_hosts
require_partnership
RAM_CACHE="/tmp/.cache/vv/d" RAM_CACHE="/tmp/.cache/vv/d"
SAVE_DIR="/boot/config/.cache/vv/d" SAVE_DIR="/boot/config/.cache/vv/d"
+1
View File
@@ -23,6 +23,7 @@ source "$SCRIPT_DIR/../load_config.sh"
parse_args "$@" parse_args "$@"
detect_hosts detect_hosts
require_partnership
RAM_CACHE="/tmp/.cache/vv/d" RAM_CACHE="/tmp/.cache/vv/d"
SAVE_DIR="/boot/config/.cache/vv/d" SAVE_DIR="/boot/config/.cache/vv/d"
+1
View File
@@ -48,6 +48,7 @@ for arg in "$@"; do
done done
parse_args "${FILTERED_ARGS[@]}" parse_args "${FILTERED_ARGS[@]}"
detect_hosts detect_hosts
require_partnership
if [[ "${CONF_SYNC_ENABLED:-true}" == false ]]; then if [[ "${CONF_SYNC_ENABLED:-true}" == false ]]; then
log "CONF_SYNC_ENABLED=false — skipping" log "CONF_SYNC_ENABLED=false — skipping"
+1
View File
@@ -26,6 +26,7 @@ source "$SCRIPT_DIR/../../load_config.sh"
parse_args "$@" parse_args "$@"
detect_hosts detect_hosts
require_partnership
[[ "${FALLBACK_ENABLED:-false}" != "true" ]] && exit 0 [[ "${FALLBACK_ENABLED:-false}" != "true" ]] && exit 0
[[ "${CONF_SYNC_ENABLED:-true}" != "true" ]] && exit 0 [[ "${CONF_SYNC_ENABLED:-true}" != "true" ]] && exit 0
+6
View File
@@ -1923,4 +1923,10 @@ show_status() {
echo "Delayed: ${DELAYED_CONTAINERS[*]:-n/a}" echo "Delayed: ${DELAYED_CONTAINERS[*]:-n/a}"
echo "Excludes: ${EXCLUDE_DIRS[*]:-n/a}" echo "Excludes: ${EXCLUDE_DIRS[*]:-n/a}"
echo "━━━━━━━━━━━━━━━━━━━━━━━" echo "━━━━━━━━━━━━━━━━━━━━━━━"
}
require_partnership() {
[[ "${PARTNERSHIP_ENABLED:-false}" == "true" ]] && return 0
log "PARTNERSHIP_ENABLED=false — skipping cross-server operation"
exit 0
} }