diff --git a/entrypoint.sh b/entrypoint.sh index c278bac..f1155e3 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,11 +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 - # LiteFS 0.5 status is nested under the 'info' object - local status=$(curl -s http://localhost:20202/status || echo '{"info": {}}') + local status=$(curl -s http://localhost:20202/status || echo "{}") - # Ensure we have valid JSON and extract isPrimary - local is_primary=$(echo "$status" | jq -r '.info.isPrimary // false' 2>/dev/null || echo "false") + # Support both LiteFS 0.5 (flat) and potential future/other versions (nested) + # We use jq to find the first truthy isPrimary value + local is_primary=$(echo "$status" | jq -r 'if type == "object" then (.isPrimary // .info.isPrimary // false) else false end' 2>/dev/null || echo "false") if [ "$is_primary" = "true" ]; then return 0 # We are the primary @@ -34,9 +34,10 @@ wait_for_litefs() { local timeout=60 local count=0 while [ $count -lt $timeout ]; do - 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") + local status=$(curl -s http://localhost:20202/status || echo "null") + + # Check if we got a valid JSON object with a definitive isPrimary status + local is_primary_val=$(echo "$status" | jq -r 'if type == "object" then (.isPrimary // .info.isPrimary // "null") else "null" end' 2>/dev/null || echo "null") if [ "$is_primary_val" != "null" ]; then local role="replica"