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
|
||||
|
||||
# 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
|
||||
35
register.sh
35
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
|
||||
Reference in New Issue
Block a user