Bring script headers onto the template and close safeguard gaps

Headers claimed protections the code never had, and several destructive paths had no
guard against a collapsed config value.
This commit is contained in:
Gmer4Lfe
2026-08-01 20:37:59 -04:00
parent cdce877601
commit e8b114094a
78 changed files with 3301 additions and 277 deletions
+38 -6
View File
@@ -45,12 +45,34 @@
# OPERATIONAL SAFEGUARDS
# ==============================================================================================
#
# Root check — ZFS scrub, SMART tests require root
# acquire_lock — prevents concurrent monthly runs
# detect_hosts() — MY_ID in notifications and logs
# Uptime gate — MONTHLY_UPTIME_THRESHOLD_DAYS must be met
# Interval gate — MONTHLY_RUN_INTERVAL_DAYS since last run must be met
# --force flag — bypasses both gates for manual override
# Root Enforcement
# ZFS scrub and SMART tests require root.
#
# Lock Acquisition
# acquire_lock prevents concurrent monthly runs. These are long jobs — a scrub can run
# for hours — and two at once would double the I/O cost for no benefit.
#
# Host Detection
# detect_hosts() sets MY_ID for notifications and logs.
#
# Empty Job List Guard
# Exits with an error and a notification if MONTHLY_MAINTENANCE_SCRIPTS is empty. A
# monthly job that silently does nothing is the hardest kind to notice missing.
#
# Uptime Gate
# MONTHLY_UPTIME_THRESHOLD_DAYS must be met before the run proceeds. Heavy full-disk
# work immediately after a boot competes with everything else still starting up.
#
# Interval Gate
# MONTHLY_RUN_INTERVAL_DAYS since the last successful run must have elapsed. The
# schedule fires more often than the work should actually happen, so the gate — not
# the cron entry — is what defines the real cadence.
#
# Force Override
# --force bypasses both gates for a deliberate manual run.
#
# Non-Fatal Steps
# A failing job is recorded and the remaining jobs still run.
#
# ==============================================================================================
# CONFIGURATION
@@ -113,6 +135,16 @@ acquire_lock
detect_hosts
# An unconfigured job list would run nothing and still report "0/0 passed" — indistinguishable
# from a healthy run. Fail loudly instead of silently doing no work.
if [[ ${#MONTHLY_MAINTENANCE_SCRIPTS[@]} -eq 0 ]]; then
error "MONTHLY_MAINTENANCE_SCRIPTS is empty — no monthly maintenance scripts will run"
error "Check MONTHLY_MAINTENANCE_SCRIPTS in master.conf"
notify "monthly maintenance scripts skipped on $(hostname) ($MY_ID) — MONTHLY_MAINTENANCE_SCRIPTS is empty" \
"$(basename "$0" .sh)" "warning"
exit 1
fi
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no scripts will be executed"
[[ "$FORCE_RUN" == true ]] && warn "FORCE — uptime and interval gates bypassed"