From 362f838f7cc93030699b9d0f493ac36d764d5798 Mon Sep 17 00:00:00 2001 From: sstent Date: Mon, 27 Apr 2026 08:25:40 -0700 Subject: [PATCH] fix: robust leadership detection via LiteFS API and resolve Navidrome deprecation warnings --- entrypoint.sh | 25 ++++++++++++++----------- navidrome-litefs.nomad | 4 ++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 58d08c9..995fb42 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,30 +15,33 @@ NAVIDROME_PID=0 # Check if this node is the LiteFS Primary check_primary() { - # Role: primary or Role: replica - local role=$(litefs status 2>/dev/null | grep "Role" | awk '{print $2}' || echo "unknown") - if [ "$role" = "primary" ]; then - return 0 # Success, we are primary + # Use the local LiteFS API to get the most accurate status + local status=$(curl -s http://localhost:20202/status || echo "{}") + local is_primary=$(echo "$status" | jq -r '.isPrimary // false') + + if [ "$is_primary" = "true" ]; then + return 0 # We are the primary fi - return 1 # Not primary + return 1 # We are a replica } -# Wait for LiteFS to be "Ready" (connected to cluster) +# Wait for LiteFS to be fully initialized and connected wait_for_litefs() { - echo "Waiting for LiteFS to initialize..." + echo "Waiting for LiteFS to settle..." local timeout=60 local count=0 while [ $count -lt $timeout ]; do - # Check if LiteFS is ready by looking for any role in status - if litefs status 2>/dev/null | grep -q "Role"; then - echo "LiteFS is initialized." + local status=$(curl -s http://localhost:20202/status || echo "{}") + # If isPrimary is not null, LiteFS has determined its role + if [ "$(echo "$status" | jq -r '.isPrimary // "null"')" != "null" ]; then + echo "LiteFS initialized. Role: $(echo "$status" | jq -r '.isPrimary | if . then "primary" else "replica" end')" return 0 fi sleep 2 count=$((count + 2)) echo -n "." done - echo "ERROR: LiteFS failed to initialize after ${timeout}s" + echo "ERROR: LiteFS failed to settle after ${timeout}s" return 1 } diff --git a/navidrome-litefs.nomad b/navidrome-litefs.nomad index 61eefe1..734d8d9 100644 --- a/navidrome-litefs.nomad +++ b/navidrome-litefs.nomad @@ -73,8 +73,8 @@ job "navidrome-litefs" { ND_SCANNER_FSWATCHER_ENABLED = "false" ND_FORCE_REDEPLOY = "5" ND_LOGLEVEL = "info" - ND_REVERSEPROXYWHITELIST = "0.0.0.0/0" - ND_REVERSEPROXYUSERHEADER = "X-Forwarded-User" + ND_EXTAUTH_TRUSTEDSOURCES = "0.0.0.0/0" + ND_EXTAUTH_USERHEADER = "X-Forwarded-User" } # NO service block here! Managed by register.sh inside the container.