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:
co-authored by
Claude Sonnet 4.6
parent
fdba23c32d
commit
46b27f609a
@@ -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
|
||||
|
||||
@@ -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 ─────────────────────────────────────────
|
||||
|
||||
@@ -719,6 +719,20 @@ check_rsync_enabled() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# ==============================================================================================
|
||||
# ── UNRAID SERVICE STATE ──────────────────────────────────────────────────────────────────────
|
||||
# ==============================================================================================
|
||||
# Reads Unraid config files to check whether Docker and VM Manager are enabled.
|
||||
# Use these guards before any script that manages containers or VMs.
|
||||
|
||||
is_docker_enabled() {
|
||||
[[ "$(grep -oP '(?<=DOCKER_ENABLED=")[^"]+' /boot/config/docker.cfg 2>/dev/null)" == "yes" ]]
|
||||
}
|
||||
|
||||
is_vm_manager_enabled() {
|
||||
[[ "$(grep -oP '(?<=SERVICE=")[^"]+' /boot/config/domain.cfg 2>/dev/null)" == "enable" ]]
|
||||
}
|
||||
|
||||
# ==============================================================================================
|
||||
# ── LOCAL HEALTH CHECKS ───────────────────────────────────────────────────────────────────────
|
||||
# ==============================================================================================
|
||||
|
||||
@@ -252,7 +252,7 @@ fi
|
||||
# ==============================================================================================
|
||||
# ━━━ Graceful VM Shutdown ━━━
|
||||
# ==============================================================================================
|
||||
if command -v virsh >/dev/null 2>&1; then
|
||||
if is_vm_manager_enabled && command -v virsh >/dev/null 2>&1; then
|
||||
VM_LIST=$(virsh list --name 2>/dev/null | grep -v "^$" || true)
|
||||
if [[ -n "$VM_LIST" ]]; then
|
||||
echo ""
|
||||
@@ -272,7 +272,11 @@ if command -v virsh >/dev/null 2>&1; then
|
||||
log "Waiting ${VM_WAIT}s for VMs to shut down..."
|
||||
sleep "$VM_WAIT"
|
||||
fi
|
||||
else
|
||||
log "VM Manager enabled but no VMs running — skipping shutdown"
|
||||
fi
|
||||
else
|
||||
log "VM Manager not enabled — skipping VM shutdown"
|
||||
fi
|
||||
|
||||
# ==============================================================================================
|
||||
@@ -280,7 +284,9 @@ fi
|
||||
# ==============================================================================================
|
||||
echo ""
|
||||
echo "━━━ $ICON_GEAR Stop VM Manager ━━━"
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
if ! is_vm_manager_enabled; then
|
||||
log "VM Manager not enabled — skipping"
|
||||
elif [[ "$DRY_RUN" == true ]]; then
|
||||
warn "DRY RUN — would stop VM Manager (libvirt)"
|
||||
else
|
||||
if /etc/rc.d/rc.libvirt stop >/dev/null 2>&1; then
|
||||
|
||||
Reference in New Issue
Block a user