unRAID_Essentials echo/log audit pass + exit traps

Exit traps: resource_watchdog registers/clears trap for stopped containers;
server_reboot registers trap to restart Docker service on abort; system_watchdog
records containers before bulk stop and registers trap to restart if reboot aborts.

echo/log audit: status conclusions, nothing-to-do, and clean-cycle confirmations
→ echo across clear_logs, docker_syslog_filter, mover_stop, php_fpm_max_children,
rsync_stop, user_scripts_stop. resource_watchdog: disabled flag, restore-level
messages, pressure status → echo. system_watchdog: clean-cycle summary → echo.
Manual-Unraid_Essentials.md: added Output Tiers section.
This commit is contained in:
Gmer4Lfe
2026-05-21 17:21:20 -04:00
parent 86b31256ed
commit 3770bf80e7
10 changed files with 78 additions and 20 deletions
+23 -6
View File
@@ -118,7 +118,7 @@ if [[ "$EUID" -ne 0 ]]; then
fi
if [[ "${RW_ENABLED:-true}" != "true" ]]; then
log "Resource Manager disabled (RW_ENABLED=false)"
echo "Resource Manager disabled (RW_ENABLED=false)"
exit 0
fi
@@ -138,6 +138,21 @@ touch "$RW_STATE_FILE" 2>/dev/null || {
exit 1
}
# ── Exit Trap — restart containers stopped this run if script crashes ──────────────────────────
declare -a _RW_TRAP_STOPPED=()
_rw_trap_restart_stopped() {
[[ ${#_RW_TRAP_STOPPED[@]} -eq 0 ]] && return
for c in "${_RW_TRAP_STOPPED[@]}"; do
[[ -z "$c" ]] && continue
if docker inspect "$c" >/dev/null 2>&1; then
warn "Exit trap: restarting $c (stopped but state not persisted)"
docker start "$c" >/dev/null 2>&1 || warn " Failed to restart $c"
fi
done
}
trap _rw_trap_restart_stopped EXIT
# ==============================================================================================
# ━━━ State Helpers ━━━
# ==============================================================================================
@@ -379,6 +394,7 @@ stop_containers() {
if timeout "$DOCKER_TIMEOUT" docker stop "$container" >/dev/null 2>&1; then
warn "Stopped $container (hard pressure)"
actually_stopped+=("$container")
_RW_TRAP_STOPPED+=("$container")
else
error "Failed to stop $container"
fi
@@ -468,7 +484,7 @@ apply_level_3() {
# ==============================================================================================
restore_level_3() {
log "Restoring from level 3 — starting stopped containers"
echo "Restoring from level 3 — starting stopped containers"
if [[ -n "$STOPPED_LIST" ]]; then
start_containers "$STOPPED_LIST"
STOPPED_LIST=""
@@ -478,7 +494,7 @@ restore_level_3() {
}
restore_level_2() {
log "Restoring from level 2 — unpausing containers"
echo "Restoring from level 2 — unpausing containers"
if [[ -n "$PAUSED_LIST" ]]; then
unpause_containers "$PAUSED_LIST"
PAUSED_LIST=""
@@ -486,7 +502,7 @@ restore_level_2() {
}
restore_level_1() {
log "Restoring from level 1 — removing downloader throttle"
echo "Restoring from level 1 — removing downloader throttle"
sabnzbd_set_speed "0"
qbit_set_dl_limit 0
}
@@ -552,9 +568,9 @@ elif [[ "$TARGET_LEVEL" -lt "$CURRENT_LEVEL" ]]; then
else
# ── Steady state ────────────────────────────────────────────────────────────────────────
if [[ "$CURRENT_LEVEL" -gt 0 ]]; then
log "Pressure holding at level $CURRENT_LEVEL — waiting for sustained recovery"
echo "Pressure holding at level $CURRENT_LEVEL — waiting for sustained recovery"
else
log "System at normal pressure ✅"
echo "System at normal pressure ✅"
fi
rm_state_set "rm_recover_cycles" 0
fi
@@ -564,5 +580,6 @@ fi
# ==============================================================================================
rm_state_set "rm_paused_containers" "$PAUSED_LIST"
rm_state_set "rm_stopped_containers" "$STOPPED_LIST"
trap - EXIT # state persisted — stopped containers recorded, trap no longer needed
# Touch state file each run so docker_watchdog stale guard sees fresh mtime
touch "$RW_STATE_FILE" 2>/dev/null