fix: support both flat and nested LiteFS status JSON and add robust type checking
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 42s

This commit is contained in:
2026-04-27 08:41:21 -07:00
parent 3e6a4d1704
commit c04c00143e

View File

@@ -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"