safeguard: check Docker/VM Manager enabled before acting

common.sh: add is_docker_enabled() and is_vm_manager_enabled() helpers
reading /boot/config/docker.cfg and /boot/config/domain.cfg.

docker_watchdog: exit cleanly if Docker not enabled in Unraid settings.
stability_watchdog: skip Docker daemon check and Docker container stop
if Docker not enabled; skip virsh VM shutdown if VM Manager not enabled.
server_reboot: skip VM shutdown and libvirt stop if VM Manager not enabled.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gmer4Lfe
2026-05-31 15:18:58 -04:00
co-authored by Claude Sonnet 4.6
parent fdba23c32d
commit 46b27f609a
4 changed files with 35 additions and 6 deletions
+5
View File
@@ -240,6 +240,11 @@ acquire_lock
# detect_hosts() sets MY_ID and aliases all HOST*_WATCHDOG_* arrays
detect_hosts
if ! is_docker_enabled; then
log "Docker not enabled in Unraid settings — skipping cycle"
exit 0
fi
if ! command -v docker >/dev/null 2>&1; then
error "Docker not found — cannot start watchdog"
exit 1
+8 -4
View File
@@ -424,17 +424,19 @@ do_reboot() {
log_reboot
# Graceful shutdown sequence
warn "Shutting down VMs..."
if command -v virsh >/dev/null 2>&1; then
if is_vm_manager_enabled && command -v virsh >/dev/null 2>&1; then
warn "Shutting down VMs..."
for VM in $(virsh list --name 2>/dev/null); do
[[ -z "$VM" ]] && continue
virsh shutdown "$VM" >/dev/null 2>&1
done
sleep 30
else
log "VM Manager not enabled — skipping VM shutdown"
fi
warn "Stopping Docker containers..."
if command -v docker >/dev/null 2>&1; then
if is_docker_enabled && command -v docker >/dev/null 2>&1; then
mapfile -t _SYS_REBOOT_STOPPED < <(docker ps --format '{{.Names}}' 2>/dev/null)
trap _trap_sys_reboot_restart EXIT
timeout 60 docker ps -q 2>/dev/null | xargs -r docker stop >/dev/null 2>&1
@@ -476,7 +478,7 @@ echo "━━━ $ICON_REBOOT Stability Watchdog — $(date '+%Y-%m-%d %H:%M:%S')
# docker_watchdog owns daemon restart attempts (strike system + rc.docker restart).
# When restart fails and daemon is confirmed down, it writes daemon_confirmed_down=true
# to WATCHDOG_STATE_FILE. We read that flag and run through the standard strike system.
if [[ "$SYS_WATCHDOG_CHECK_DOCKER_DAEMON" == true ]]; then
if [[ "$SYS_WATCHDOG_CHECK_DOCKER_DAEMON" == true ]] && is_docker_enabled; then
_daemon_down=$(grep -oP "(?<=^daemon_confirmed_down:)[^:]*" "$WATCHDOG_STATE_FILE" 2>/dev/null || echo "false")
TRIGGERED=false
[[ "$_daemon_down" == "true" ]] && TRIGGERED=true
@@ -484,6 +486,8 @@ echo "━━━ $ICON_REBOOT Stability Watchdog — $(date '+%Y-%m-%d %H:%M:%S')
TRIGGERS+=("docker_daemon_unresponsive")
[[ "$TRIGGERED" == true ]] && log "Docker daemon confirmed down — strike toward reboot" || \
log "Docker daemon flag clear ✅"
elif [[ "$SYS_WATCHDOG_CHECK_DOCKER_DAEMON" == true ]]; then
log "Docker not enabled — skipping daemon check"
fi
# ── rootfs critical — at 99%+ writes are failing ─────────────────────────────────────────