fix: unescaped quotes in register.sh and added logging
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m3s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m3s
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Start the registration loop in the background
|
# Start the registration loop in the background, redirecting output to stderr so we see it in Nomad logs
|
||||||
/usr/local/bin/register.sh &
|
/usr/local/bin/register.sh >&2 &
|
||||||
|
|
||||||
# Start Navidrome
|
# Start Navidrome
|
||||||
# LiteFS has already mounted the DB at this point because it's the supervisor
|
|
||||||
echo "Starting Navidrome..."
|
echo "Starting Navidrome..."
|
||||||
/app/navidrome
|
/app/navidrome
|
||||||
35
register.sh
35
register.sh
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -x
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
SERVICE_NAME="navidrome"
|
SERVICE_NAME="navidrome"
|
||||||
@@ -19,17 +20,17 @@ register_service() {
|
|||||||
local tags=$2
|
local tags=$2
|
||||||
local id="navidrome-${NODE_IP}-${name}"
|
local id="navidrome-${NODE_IP}-${name}"
|
||||||
|
|
||||||
echo "Registering as ${name}..."
|
echo "Registering as ${name} with ID ${id} at ${NODE_IP}:${PORT}..."
|
||||||
curl -s -X PUT -d "{
|
curl -v -X PUT -d "{
|
||||||
"ID": "${id}",
|
\"ID\": \"${id}\",
|
||||||
"Name": "${name}",
|
\"Name\": \"${name}\",
|
||||||
"Tags": ${tags},
|
\"Tags\": ${tags},
|
||||||
"Address": "${NODE_IP}",
|
\"Address\": \"${NODE_IP}\",
|
||||||
"Port": ${PORT},
|
\"Port\": ${PORT},
|
||||||
"Check": {
|
\"Check\": {
|
||||||
"HTTP": "http://${NODE_IP}:${PORT}/app",
|
\"HTTP\": \"http://${NODE_IP}:${PORT}/app\",
|
||||||
"Interval": "${CHECK_INTERVAL}",
|
\"Interval\": \"${CHECK_INTERVAL}\",
|
||||||
"Timeout": "2s"
|
\"Timeout\": \"2s\"
|
||||||
}
|
}
|
||||||
}" "${CONSUL_HTTP_ADDR}/v1/agent/service/register"
|
}" "${CONSUL_HTTP_ADDR}/v1/agent/service/register"
|
||||||
}
|
}
|
||||||
@@ -37,8 +38,8 @@ register_service() {
|
|||||||
deregister_service() {
|
deregister_service() {
|
||||||
local name=$1
|
local name=$1
|
||||||
local id="navidrome-${NODE_IP}-${name}"
|
local id="navidrome-${NODE_IP}-${name}"
|
||||||
echo "Deregistering ${name}..."
|
echo "Deregistering ${name} with ID ${id}..."
|
||||||
curl -s -X PUT "${CONSUL_HTTP_ADDR}/v1/agent/service/deregister/${id}"
|
curl -v -X PUT "${CONSUL_HTTP_ADDR}/v1/agent/service/deregister/${id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Starting Consul registration loop..."
|
echo "Starting Consul registration loop..."
|
||||||
@@ -46,14 +47,16 @@ echo "Starting Consul registration loop..."
|
|||||||
LAST_STATE="unknown"
|
LAST_STATE="unknown"
|
||||||
|
|
||||||
while true; do
|
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"
|
CURRENT_STATE="primary"
|
||||||
else
|
else
|
||||||
CURRENT_STATE="replica"
|
CURRENT_STATE="replica"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Current node state: ${CURRENT_STATE}"
|
||||||
|
|
||||||
if [ "$CURRENT_STATE" != "$LAST_STATE" ]; then
|
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
|
if [ "$CURRENT_STATE" == "primary" ]; then
|
||||||
deregister_service "$REPLICA_SERVICE_NAME"
|
deregister_service "$REPLICA_SERVICE_NAME"
|
||||||
register_service "$SERVICE_NAME" "$PRIMARY_TAGS"
|
register_service "$SERVICE_NAME" "$PRIMARY_TAGS"
|
||||||
@@ -65,4 +68,4 @@ while true; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 15
|
sleep 15
|
||||||
done
|
done
|
||||||
Reference in New Issue
Block a user