diff --git a/Arrs_Stack/start_webhook_listener.sh b/Arrs_Stack/start_webhook_listener.sh index fca4e4c..91b3b0a 100755 --- a/Arrs_Stack/start_webhook_listener.sh +++ b/Arrs_Stack/start_webhook_listener.sh @@ -27,8 +27,9 @@ # ============================================================================================== # # 1. Check WEBHOOK_PORT — exit cleanly if 0 (listener disabled) -# 2. Check WEBHOOK_SECRET — generate and persist one if empty -# 3. exec node webhook_listener.js — replaces this process; PID stays the same +# 2. acquire_lock "continuous" — exit cleanly if a healthy instance is already running +# 3. Check WEBHOOK_SECRET — generate and persist one if empty +# 4. exec node webhook_listener.js — replaces this process; PID stays the same # # exec is intentional: array_started.sh tracks the PID of this script to check # whether the listener is running. exec preserves that PID across the hand-off @@ -53,11 +54,22 @@ # PID of this script to check liveness — exec ensures that PID continues to # refer to the running node process after the hand-off. # +# Continuous-Mode Lock, Not Just PID Tracking +# array_started.sh only checks whether ITS launch attempt is still alive after +# 1s — it has no idea a previous instance might already be listening (e.g. an +# array stop/start that didn't kill the old node process). Without its own +# guard, a relaunch would exec straight into node, hit EADDRINUSE on the port, +# exit 1 almost immediately, and array_started.sh would log a false failure +# for a listener that was actually still healthy. acquire_lock "continuous" +# detects the live instance and exits 0 instead. +# # ============================================================================================== # OPERATIONAL SAFEGUARDS # ============================================================================================== # # WEBHOOK_PORT=0 gate — exits cleanly before any setup if the listener is disabled +# acquire_lock "continuous" — exits 0 cleanly if a healthy instance is already running, +# instead of relaunching into a port conflict # Secret auto-generate — WEBHOOK_SECRET generated via openssl rand if empty; # persisted to master.conf immediately so restarts reuse it # Shared secret gate — webhook URL must include ?key=; @@ -97,6 +109,11 @@ source "$ECOSYSTEM_ROOT/load_config.sh" exit 0 } +# Skip gracefully if a healthy instance is already listening — otherwise a +# restart that doesn't kill the old node process (array stop/start without a +# full reboot) hits EADDRINUSE and array_started.sh logs a false failure. +acquire_lock "continuous" + # ── Auto-generate secret if not yet set ───────────────────────────────────── if [[ -z "${WEBHOOK_SECRET:-}" ]]; then GENERATED=$(openssl rand -hex 32)