fix: revert to original data paths and add ND_ARTISTIMAGEFOLDER
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 43s

This commit is contained in:
2026-04-27 14:07:08 -07:00
parent 92f9209dcd
commit e678120572
9 changed files with 52 additions and 148 deletions

View File

@@ -5,7 +5,6 @@ SERVICE_ID="${SERVICE_NAME}-${NOMAD_ALLOC_ID:-$(hostname)}"
PORT=4533
CONSUL_HTTP_ADDR="${CONSUL_URL:-http://localhost:8500}"
NODE_IP="${ADVERTISE_IP}"
DB_LOCK_FILE="/litefs/.primary"
NAVIDROME_PID=0
# Tags for the Primary service (Traefik enabled)
@@ -14,7 +13,6 @@ PRIMARY_TAGS='["navidrome","web","traefik.enable=true","urlprefix-/navidrome","t
# --- Helper Functions ---
# Check if this node is the LiteFS Primary
# LiteFS 0.5 status API returns a flat object: {"isPrimary": true, ...}
check_primary() {
local status=$(curl -s http://localhost:20202/info || echo "{}")
local is_primary=$(echo "$status" | jq -r 'if type == "object" then (.isPrimary // false) else false end' 2>/dev/null || echo "false")
@@ -48,6 +46,25 @@ wait_for_litefs() {
return 1
}
# Backup Database (Only on Primary)
run_backup() {
local backup_dir="/shared_data/backup"
local timestamp=$(date +%Y%m%d_%H%M%S)
local backup_file="${backup_dir}/navidrome.db_${timestamp}.bak"
echo "Backing up database to ${backup_file}..."
mkdir -p "$backup_dir"
if litefs export -name navidrome.db "$backup_file"; then
echo "Backup successful."
# Keep only last 7 days
find "$backup_dir" -name "navidrome.db_*.bak" -mtime +7 -delete
echo "Old backups cleaned."
else
echo "ERROR: Backup failed!"
fi
}
# Register Service with TTL Check
register_service() {
echo "Registering service ${SERVICE_ID} with Consul..."
@@ -79,24 +96,19 @@ deregister_service() {
start_app() {
echo "Node is Primary. Starting Navidrome..."
# Ensure shared directories exist on persistent host volume
mkdir -p /local/navidrome_v2/plugins /local/navidrome_v2/cache /local/navidrome_v2/backup
# Ensure shared directories exist
mkdir -p /shared_data/plugins /shared_data/cache /shared_data/backup /shared_data/artist_images
# 1. Set the DataFolder to the local task mount
export ND_DATAFOLDER="/local/navidrome_v2"
# 2. Redirect other folders just in case
export ND_CACHEFOLDER="/local/navidrome_v2/cache"
export ND_BACKUP_PATH="/local/navidrome_v2/backup"
export ND_PLUGINS_FOLDER="/local/navidrome_v2/plugins"
# 3. Start Navidrome with ND_DBPATH environment variable.
# This is the most authoritative way to set the DB location.
export ND_DBPATH="/litefs/navidrome_v2.db?_busy_timeout=15000"
# Configuration
export ND_DATAFOLDER="/data"
export ND_CACHEFOLDER="/shared_data/cache"
export ND_BACKUP_PATH="/shared_data/backup"
export ND_PLUGINS_FOLDER="/shared_data/plugins"
export ND_ARTISTIMAGEFOLDER="/shared_data/artist_images"
/app/navidrome &
NAVIDROME_PID=$!
echo "Navidrome running (PID: $NAVIDROME_PID) with database at /litefs"
echo "Navidrome running (PID: $NAVIDROME_PID) with data folder at /data"
}
# Stop Navidrome
@@ -124,6 +136,9 @@ trap cleanup TERM INT
echo "Starting Supervisor. Waiting for leadership settle..."
wait_for_litefs || exit 1
LAST_BACKUP_TIME=$(date +%s)
BACKUP_INTERVAL=86400 # 24 hours
while true; do
if check_primary; then
# === WE ARE PRIMARY ===
@@ -132,6 +147,13 @@ while true; do
register_service
fi
pass_ttl
# Handle periodic backup
CURRENT_TIME=$(date +%s)
if [ $((CURRENT_TIME - LAST_BACKUP_TIME)) -ge $BACKUP_INTERVAL ]; then
run_backup
LAST_BACKUP_TIME=$CURRENT_TIME
fi
else
# === WE ARE REPLICA ===
if [ "${NAVIDROME_PID}" -gt 0 ]; then