fix 9 bugs in partnership offboard flow

partnership_manager.sh:
- fix auto-offboard threshold: × 96 → × 48 (was triggering at 2× configured days)
- fix do_final_sync(): use CRITICAL_SYNC_SHARES if configured; fall back to hardcoded paths
- replace inline --check offboard blocks with background partnership_offboard.sh calls:
  • owner path was missing remote container cleanup (steps 8+9) and blocklist
  • mirror path was missing blocklist, SSH revocation, CRITICAL_RSYNC_ENABLED=false
  • local grace_seconds outside a function (bash error) eliminated with the block removal
  • 6hr Tailscale grace sleep was blocking the cron for the full grace window

partnership_offboard.sh:
- reorder owner path: state write moved from step 5 to step 10 (last) so re-running
  after a mid-offboard crash restarts from scratch instead of exiting as INACTIVE;
  state is now written before the Tailscale grace sleep so --check stops re-triggering
- add FolderView3 remote folder cleanup in step 7 (mirror's fallback folder persisted)
- track step 1+2 outcome with STEP_STOP_OK / STEP_SYNC_OK; summary now reflects actual
  result instead of hardcoding  regardless of dry-run or failure
- update header step list to match new step order
This commit is contained in:
Gmer4Lfe
2026-05-23 09:24:34 -04:00
parent 14a74939e6
commit fda853eed8
2 changed files with 121 additions and 118 deletions
+34 -57
View File
@@ -1123,18 +1123,30 @@ check_both_healthy() {
}
do_final_sync() {
log "Running final Critical-Data and Emby sync..."
log "Running final critical sync..."
if [[ "$DRY_RUN" == false ]]; then
# Use CRITICAL_SYNC_SHARES from HOST* conf if available
# Falls back to known paths — these are the critical ones
bash "$SCRIPT_DIR/../Rsync/rsync.sh" \
"/mnt/user/appdata-Fallback/Critical-Data" \
--profile=critical-fallback --log
bash "$SCRIPT_DIR/../Rsync/rsync.sh" \
"/mnt/user/Media_Server/Emby" \
--profile=emby-fallback --log
if [[ "${#CRITICAL_SYNC_SHARES[@]}" -gt 0 ]]; then
for _share in "${CRITICAL_SYNC_SHARES[@]}"; do
[[ -z "$_share" ]] && continue
local _path="${_share%%|*}"
local _profile="${_share##*|}"
if [[ "$_path" == "$_profile" ]]; then
bash "$SCRIPT_DIR/../Rsync/rsync.sh" "$_path" --log
else
bash "$SCRIPT_DIR/../Rsync/rsync.sh" "$_path" \
--profile="$_profile" --log
fi
done
else
bash "$SCRIPT_DIR/../Rsync/rsync.sh" \
"/mnt/user/appdata-Fallback/Critical-Data" \
--profile=critical-fallback --log
bash "$SCRIPT_DIR/../Rsync/rsync.sh" \
"/mnt/user/Media_Server/Emby" \
--profile=emby-fallback --log
fi
else
warn "DRY RUN — would run final Critical-Data and Emby sync"
warn "DRY RUN — would run final critical sync (${#CRITICAL_SYNC_SHARES[@]:-hardcoded} shares)"
fi
warn "Final sync complete — mirror has current state ✅"
}
@@ -1317,7 +1329,7 @@ if [[ "$MODE" == "check" ]]; then
echo "$OFFLINE_COUNT" > "$OFFLINE_COUNTER"
# Auto-offboard threshold: threshold_days × 48 intervals/day (every 30min)
THRESHOLD_INTERVALS=$(( ${PARTNERSHIP_OFFLINE_THRESHOLD:-30} * 96 ))
THRESHOLD_INTERVALS=$(( ${PARTNERSHIP_OFFLINE_THRESHOLD:-30} * 48 ))
if [[ "$OFFLINE_COUNT" -ge "$THRESHOLD_INTERVALS" ]]; then
warn "Remote offline for ${PARTNERSHIP_OFFLINE_THRESHOLD} days — triggering auto-offboard"
notify "Partnership auto-offboard on $(hostname)$REMOTE_SERVER_NAME offline for ${PARTNERSHIP_OFFLINE_THRESHOLD} days" \
@@ -1360,56 +1372,21 @@ if [[ "$MODE" == "check" ]]; then
exit 0
fi
# Remote requested offboard
# Remote requested offboard — run full offboard in background so cron is not blocked
if [[ "$REMOTE_STATE" == "INACTIVE" ]] && [[ "$LOCAL_STATE" == "ACTIVE" ]]; then
warn "Partnership check — $REMOTE_SERVER_NAME requested offboard"
if [[ "$AM_OWNER" == true ]]; then
warn "Owner finalising offboard request from mirror..."
do_final_sync
# Remove owner's fallback containers, restart own stack
cleanup_partner_containers "$(derive_partner_folder_name "$MIRROR")"
start_own_stack
NOW=$(date '+%Y-%m-%d %H:%M:%S')
write_state_file "$LOCAL_STATE_FILE" \
"INACTIVE" "" "$NOW" "$REMOTE_SERVER_NAME" "mirror-requested"
if [[ "$DRY_RUN" == false ]]; then
update_master_conf "CRITICAL_RSYNC_ENABLED" "false"
fi
# SSH key revocation — mutual, both directions
# REMOTE_IP already resolved above — this is the last SSH operation
SSH_REVOKE_REMOTE_OK=false
SSH_REVOKE_LOCAL_OK=false
do_ssh_key_revocation "$REMOTE_IP"
if [[ "${PARTNERSHIP_REMOVE_TAILSCALE:-true}" == true ]]; then
local grace_seconds=$(( ${PARTNERSHIP_GRACE_HOURS:-6} * 3600 ))
warn "Waiting ${PARTNERSHIP_GRACE_HOURS:-6}hr grace period..."
# Grace sleep — interruptible via SIGTERM trap
if [[ "$DRY_RUN" == false ]]; then
trap 'warn "Partnership check interrupted during grace sleep"; exit 0' SIGTERM SIGINT
sleep "$grace_seconds"
trap - SIGTERM SIGINT
fi
remove_tailscale_device "$MIRROR"
fi
notify "Partnership offboard finalised — $MIRROR requested separation" \
"Partnership" "normal"
warn "Owner finalising offboard — spawning partnership_offboard.sh in background"
nohup bash "$SCRIPT_DIR/partnership_offboard.sh" \
--reason=mirror-requested \
>> /var/log/partnership_offboard.log 2>&1 &
warn "Offboard PID $! running — tail /var/log/partnership_offboard.log to follow"
else
# Mirror sees owner is INACTIVE — clean up own side
warn "Owner has offboarded — cleaning up mirror side..."
reconfigure_local_webuis "localhost"
cleanup_partner_containers "$(derive_partner_folder_name "$OWNER")"
start_own_stack
NOW=$(date '+%Y-%m-%d %H:%M:%S')
write_state_file "$LOCAL_STATE_FILE" \
"INACTIVE" "" "$NOW" "$OWNER" "owner-offboarded"
notify "Partnership ended — $OWNER offboarded. Auth WebUIs → localhost." \
"Partnership" "normal"
warn "Owner offboarded — spawning mirror-side cleanup in background"
nohup bash "$SCRIPT_DIR/partnership_offboard.sh" \
--reason=owner-offboarded \
>> /var/log/partnership_offboard.log 2>&1 &
warn "Offboard PID $! running — tail /var/log/partnership_offboard.log to follow"
fi
exit 0
fi