From 32d68201fdeb2f0882faa11b1a9cb264049f0a0e Mon Sep 17 00:00:00 2001 From: sascha Date: Mon, 7 Sep 2026 11:38:28 +0200 Subject: [PATCH] movetdarr v5: FD-based lease lock on local /config filesystem (NFS flock fix) --- usenet-scripts/movetdarr.sh | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/usenet-scripts/movetdarr.sh b/usenet-scripts/movetdarr.sh index 4e8024f..f1a19f2 100644 --- a/usenet-scripts/movetdarr.sh +++ b/usenet-scripts/movetdarr.sh @@ -1,9 +1,9 @@ #!/bin/bash -# movetdarr.sh v4 — SABnzbd -> FileFlows with durable n8n handoff lease +# movetdarr.sh v5 — SABnzbd -> FileFlows with durable n8n handoff lease # Categories: serien4k->Sonarr UHD, serien->Sonarr FHD, # video4k->Radarr UHD, video->Radarr FHD. -# v4: flock-Serialisierung des Lease-Blocks gegen n8n-staticData-Race -# bei parallelen SAB-Aufträgen (Last-Writer-Wins verschluckt Jobs). +# v5: BusyBox-kompatibler FD-Lock auf lokalem /config-Dateisystem. +# Der alte Lock unter /usenet lag auf NFS und konnte dauerhaft fehlschlagen. DIR="$1" NZB_NAME="$2" @@ -17,7 +17,7 @@ SOURCE_ROOT="${SOURCE_ROOT:-/usenet/complete}" DEST_ROOT="${DEST_ROOT:-/tdarr/complete}" POLL_SECONDS="${POLL_SECONDS:-60}" MAX_POLLS="${MAX_POLLS:-1440}" # 24 hours -LEASE_LOCK="${LEASE_LOCK:-/usenet/scripts/.movetdarr.lease.lock}" +LEASE_LOCK="${LEASE_LOCK:-/config/.movetdarr.lease.lock}" log() { echo "$(date '+%d.%m.%Y %H:%M:%S'): $1" >> "$LOGFILE"; } @@ -42,7 +42,7 @@ notify_failure() { handoff "$payload" >/dev/null 2>&1 || true } -log "Start v4 - Kategorie=$CATEGORY Status=$STATUS Dir=$DIR" +log "Start v5 - Kategorie=$CATEGORY Status=$STATUS Dir=$DIR" if [ "$STATUS" != "0" ]; then log "Download fehlgeschlagen, ueberspringe" @@ -145,21 +145,32 @@ register_lease() { } if command -v flock >/dev/null 2>&1; then - # BusyBox flock hat kein -w (timeout) → -n (non-blocking) mit Retry-Loop + # BusyBox flock hat kein -w: FD öffnen und -n mit Retry-Loop verwenden. + # Der FD bleibt bis nach start -> mv -> moved offen und wird vor dem + # lang laufenden Status-Polling ausdrücklich entsperrt. + exec 9>"$LEASE_LOCK" || { + log "FEHLER: Lease-Lock-Datei konnte nicht geoeffnet werden - kein Move" + exit 1 + } LEASE_ACQUIRED=false for i in $(seq 1 900); do - if flock -n "$LEASE_LOCK" -c true 2>/dev/null; then + if flock -n 9 2>/dev/null; then LEASE_ACQUIRED=true break fi sleep 1 done if [ "$LEASE_ACQUIRED" != "true" ]; then - log "WARNUNG: Lease-Lock nach 15 Minuten nicht erhalten; fahre ohne Lock fort" + log "FEHLER: Lease-Lock nach 15 Minuten nicht erhalten - kein Move" + exec 9>&- + exit 1 fi register_lease + flock -u 9 + exec 9>&- else - register_lease + log "FEHLER: flock fehlt - kein sicherer Handoff und kein Move" + exit 1 fi # Ab hier: Status-Polling ohne Lock (lang laufend, stoert keine andere Registrierung).