fix: correct jq path for LiteFS 0.5 status API and add robust error handling
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:31:47 -07:00
parent 362f838f7c
commit 3e6a4d1704

View File

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