From 3e6a4d1704b411f22514ed37dedac0b79be7a7e5 Mon Sep 17 00:00:00 2001 From: sstent Date: Mon, 27 Apr 2026 08:31:47 -0700 Subject: [PATCH] fix: correct jq path for LiteFS 0.5 status API and add robust error handling --- entrypoint.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 995fb42..c278bac 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,8 +16,11 @@ NAVIDROME_PID=0 # Check if this node is the LiteFS Primary check_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') + # LiteFS 0.5 status is nested under the 'info' object + local status=$(curl -s http://localhost:20202/status || echo '{"info": {}}') + + # Ensure we have valid JSON and extract isPrimary + local is_primary=$(echo "$status" | jq -r '.info.isPrimary // false' 2>/dev/null || echo "false") if [ "$is_primary" = "true" ]; then return 0 # We are the primary @@ -31,10 +34,14 @@ wait_for_litefs() { local timeout=60 local count=0 while [ $count -lt $timeout ]; do - 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')" + local status=$(curl -s http://localhost:20202/status || echo '{"info": {}}') + # If info.isPrimary is not null, LiteFS has determined its role + local is_primary_val=$(echo "$status" | jq -r '.info.isPrimary // "null"' 2>/dev/null || echo "null") + + if [ "$is_primary_val" != "null" ]; then + local role="replica" + if [ "$is_primary_val" = "true" ]; then role="primary"; fi + echo "LiteFS initialized. Role: $role" return 0 fi sleep 2