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
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 42s
This commit is contained in:
@@ -16,8 +16,11 @@ NAVIDROME_PID=0
|
|||||||
# Check if this node is the LiteFS Primary
|
# Check if this node is the LiteFS Primary
|
||||||
check_primary() {
|
check_primary() {
|
||||||
# Use the local LiteFS API to get the most accurate status
|
# Use the local LiteFS API to get the most accurate status
|
||||||
local status=$(curl -s http://localhost:20202/status || echo "{}")
|
# LiteFS 0.5 status is nested under the 'info' object
|
||||||
local is_primary=$(echo "$status" | jq -r '.isPrimary // false')
|
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
|
if [ "$is_primary" = "true" ]; then
|
||||||
return 0 # We are the primary
|
return 0 # We are the primary
|
||||||
@@ -31,10 +34,14 @@ wait_for_litefs() {
|
|||||||
local timeout=60
|
local timeout=60
|
||||||
local count=0
|
local count=0
|
||||||
while [ $count -lt $timeout ]; do
|
while [ $count -lt $timeout ]; do
|
||||||
local status=$(curl -s http://localhost:20202/status || echo "{}")
|
local status=$(curl -s http://localhost:20202/status || echo '{"info": {}}')
|
||||||
# If isPrimary is not null, LiteFS has determined its role
|
# If info.isPrimary is not null, LiteFS has determined its role
|
||||||
if [ "$(echo "$status" | jq -r '.isPrimary // "null"')" != "null" ]; then
|
local is_primary_val=$(echo "$status" | jq -r '.info.isPrimary // "null"' 2>/dev/null || echo "null")
|
||||||
echo "LiteFS initialized. Role: $(echo "$status" | jq -r '.isPrimary | if . then "primary" else "replica" end')"
|
|
||||||
|
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
|
return 0
|
||||||
fi
|
fi
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|||||||
Reference in New Issue
Block a user