#!/bin/bash # ============================================================================================== # ================================= Lidarr Cache Prefill ======================================== # ============================================================================================== # # PURPOSE # ───────────────────────────────────────────────────────────────────────────── # Populates the shared Lidarr tracked-data cache (see lidarr_get_tracked_data() in common.sh) # once at array start, before any other script needs it. Without this, the cache stays cold # from boot until whichever Lidarr-touching script happens to run first and write through — # which could be hours, depending on the daily schedule. One-shot: runs and exits. # # ============================================================================================== # OPERATIONAL MODEL # ============================================================================================== # # Lidarr's container may still be starting when this fires (array just started) — retries # reaching the API for up to LIDARR_PREFILL_WAIT_MINUTES before giving up. Not fatal if it # never comes up in time; the cache just stays cold until the next script writes through # naturally, exactly as it would without this script existing at all. # # ============================================================================================== # CONFIGURATION # ============================================================================================== # # host*.conf # HOST1_LIDARR_URL / HOST1_LIDARR_API_KEY — aliased by detect_hosts() # # master.conf # LIDARR_PREFILL_WAIT_MINUTES — how long to retry reaching Lidarr before giving up (default 10) # # ============================================================================================== SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/../load_config.sh" parse_args "$@" if [[ "$EUID" -ne 0 ]]; then error "Must be run as root" exit 1 fi if ! command -v jq >/dev/null 2>&1; then warn "jq not found — skipping Lidarr cache prefill" exit 0 fi acquire_lock detect_hosts if [[ -z "${LIDARR_URL:-}" ]] || [[ -z "${LIDARR_API_KEY:-}" ]]; then info "Lidarr not configured on $MY_ID ($LOCAL_SERVER_NAME) — nothing to prefill" exit 0 fi WAIT_MINUTES="${LIDARR_PREFILL_WAIT_MINUTES:-10}" WAITED=0 until check_api "$LIDARR_URL" "Lidarr" 5 >/dev/null 2>&1; do if [[ "$WAITED" -ge $(( WAIT_MINUTES * 60 )) ]]; then warn "Lidarr not reachable after ${WAIT_MINUTES}m — leaving cache cold, next script will write through" exit 0 fi sleep 15 (( WAITED += 15 )) done ARTISTS=$(arr_api "$LIDARR_URL" "$LIDARR_API_KEY" "v1" "artist" "Lidarr") || { warn "Could not fetch artists for cache prefill — leaving cache cold" exit 0 } if lidarr_cache_write "$ARTISTS"; then log "$ICON_DONE Lidarr cache prefilled ($(echo "$ARTISTS" | jq 'length') artists)" else warn "Failed to write Lidarr cache prefill" fi exit 0