fixed arrs clean up showing only orphans
This commit is contained in:
@@ -720,25 +720,18 @@ acquire_lock() {
|
||||
warn "Stale lock detected for $script_name (PID $existing_pid gone) — clearing"
|
||||
rm -f "$lockfile"
|
||||
else
|
||||
# Lock is active — check age
|
||||
# Lock is active — check age (skip warning for continuous scripts)
|
||||
local lock_age
|
||||
lock_age=$(( $(date +%s) - $(stat -c %Y "$lockfile" 2>/dev/null || echo 0) ))
|
||||
if [[ "$lock_age" -gt "$LOCK_WARN_AGE" ]]; then
|
||||
if [[ "$lock_age" -gt "$LOCK_WARN_AGE" ]] && [[ "$mode" != "continuous" ]]; then
|
||||
warn "$script_name has been running for ${lock_age}s — may be stuck (PID $existing_pid)"
|
||||
fi
|
||||
|
||||
if [[ "$mode" == "continuous" ]]; then
|
||||
# Continuous scripts (watchdogs, failover) — healthy instance = skip gracefully
|
||||
# Only force-restart if PID is stuck/unresponsive beyond LOCK_WARN_AGE
|
||||
if [[ "$lock_age" -gt "$LOCK_WARN_AGE" ]]; then
|
||||
warn "$script_name appears stuck (running ${lock_age}s) — clearing and restarting"
|
||||
kill "$existing_pid" 2>/dev/null
|
||||
sleep 2
|
||||
rm -f "$lockfile"
|
||||
else
|
||||
log "$ICON_SKIP $script_name already running healthy (PID $existing_pid) — skipping"
|
||||
exit 0
|
||||
fi
|
||||
# Continuous scripts (watchdogs, failover) — healthy instance = always skip
|
||||
# PID is alive and responding — this is correct behavior, not stuck
|
||||
log "$ICON_SKIP $script_name already running healthy (PID $existing_pid) — skipping"
|
||||
exit 0
|
||||
elif [[ "$mode" == "wait" ]]; then
|
||||
info "Another instance of $script_name is running — waiting up to ${LOCK_WAIT_TIMEOUT}s"
|
||||
local waited=0
|
||||
@@ -857,6 +850,41 @@ _release_rsync_on_exit() {
|
||||
# Verifies API endpoint is reachable before attempting operations
|
||||
# Usage: check_api "http://localhost:8989" "Sonarr" || exit 1
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# translate_path — translate container path to host path using a PATH_MAP array
|
||||
# Used by arr cleanup scripts — arrs store paths using container mounts, not host paths
|
||||
#
|
||||
# Usage:
|
||||
# translate_path "/ext-music/Artist/Album/track.flac" HOST1_LIDARR_PATH_MAP
|
||||
# Returns: /mnt/user/Music-New/Artist/Album/track.flac
|
||||
#
|
||||
# If no match found in PATH_MAP — returns path unchanged
|
||||
# Handles longest-match first to avoid partial path collisions
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
translate_path() {
|
||||
local api_path="$1"
|
||||
local -n _path_map="$2" # nameref to the associative array
|
||||
|
||||
local best_match=""
|
||||
local best_len=0
|
||||
|
||||
# Find longest matching prefix (handles overlapping container paths)
|
||||
for container_path in "${!_path_map[@]}"; do
|
||||
if [[ "$api_path" == "$container_path"* ]]; then
|
||||
if [[ "${#container_path}" -gt "$best_len" ]]; then
|
||||
best_match="$container_path"
|
||||
best_len="${#container_path}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -n "$best_match" ]]; then
|
||||
echo "${_path_map[$best_match]}${api_path#$best_match}"
|
||||
else
|
||||
echo "$api_path" # no match — return unchanged
|
||||
fi
|
||||
}
|
||||
|
||||
check_api() {
|
||||
local url="$1"
|
||||
local service="${2:-API}"
|
||||
|
||||
Reference in New Issue
Block a user