From 99d9e00fc9be395d4cf0a00524d62c869cf349b3 Mon Sep 17 00:00:00 2001 From: sstent Date: Sat, 7 Feb 2026 18:17:58 -0800 Subject: [PATCH] fix: unescaped quotes in register.sh and added logging --- entrypoint.sh | 7 +++---- register.sh | 35 +++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1d28961..6306967 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,9 +1,8 @@ #!/bin/bash -# Start the registration loop in the background -/usr/local/bin/register.sh & +# Start the registration loop in the background, redirecting output to stderr so we see it in Nomad logs +/usr/local/bin/register.sh >&2 & # Start Navidrome -# LiteFS has already mounted the DB at this point because it's the supervisor echo "Starting Navidrome..." -/app/navidrome +/app/navidrome \ No newline at end of file diff --git a/register.sh b/register.sh index a0b905e..3f7a794 100644 --- a/register.sh +++ b/register.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -x # Configuration SERVICE_NAME="navidrome" @@ -19,17 +20,17 @@ register_service() { local tags=$2 local id="navidrome-${NODE_IP}-${name}" - echo "Registering as ${name}..." - curl -s -X PUT -d "{ - "ID": "${id}", - "Name": "${name}", - "Tags": ${tags}, - "Address": "${NODE_IP}", - "Port": ${PORT}, - "Check": { - "HTTP": "http://${NODE_IP}:${PORT}/app", - "Interval": "${CHECK_INTERVAL}", - "Timeout": "2s" + echo "Registering as ${name} with ID ${id} at ${NODE_IP}:${PORT}..." + curl -v -X PUT -d "{ + \"ID\": \"${id}\", + \"Name\": \"${name}\", + \"Tags\": ${tags}, + \"Address\": \"${NODE_IP}\", + \"Port\": ${PORT}, + \"Check\": { + \"HTTP\": \"http://${NODE_IP}:${PORT}/app\", + \"Interval\": \"${CHECK_INTERVAL}\", + \"Timeout\": \"2s\" } }" "${CONSUL_HTTP_ADDR}/v1/agent/service/register" } @@ -37,8 +38,8 @@ register_service() { deregister_service() { local name=$1 local id="navidrome-${NODE_IP}-${name}" - echo "Deregistering ${name}..." - curl -s -X PUT "${CONSUL_HTTP_ADDR}/v1/agent/service/deregister/${id}" + echo "Deregistering ${name} with ID ${id}..." + curl -v -X PUT "${CONSUL_HTTP_ADDR}/v1/agent/service/deregister/${id}" } echo "Starting Consul registration loop..." @@ -46,14 +47,16 @@ echo "Starting Consul registration loop..." LAST_STATE="unknown" while true; do - if /usr/local/bin/litefs is-primary > /dev/null 2>&1; then + if /usr/local/bin/litefs is-primary; then CURRENT_STATE="primary" else CURRENT_STATE="replica" fi + echo "Current node state: ${CURRENT_STATE}" + if [ "$CURRENT_STATE" != "$LAST_STATE" ]; then - echo "State changed from ${LAST_STATE} to ${CURRENT_STATE}" + echo "State change detected: ${LAST_STATE} -> ${CURRENT_STATE}" if [ "$CURRENT_STATE" == "primary" ]; then deregister_service "$REPLICA_SERVICE_NAME" register_service "$SERVICE_NAME" "$PRIMARY_TAGS" @@ -65,4 +68,4 @@ while true; do fi sleep 15 -done +done \ No newline at end of file