Updated framework

This commit is contained in:
2026-03-27 16:50:20 +00:00
parent 24c7a481c8
commit 4faf5d2b96
11 changed files with 994 additions and 398 deletions
+113 -41
View File
@@ -18,63 +18,135 @@ set -e
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
# Load central config
load_master_conf
# Parse CLI args (flags + VAR=value)
parse_args "$@"
# Validate REBOOT_SLEEP
# STATUS MODE
if [[ "$SHOW_STATUS" == true ]]; then
echo
echo "=================================================="
echo " ️ REBOOT STATUS"
echo "--------------------------------------------------"
echo " ⏱ Delay: ${REBOOT_SLEEP:-0}s"
echo " 🧪 Dry Run: $DRY_RUN"
echo "=================================================="
exit 0
fi
# CONFIG
validate_int REBOOT_SLEEP "$REBOOT_SLEEP"
# --- Functions
# HEADER
echo
echo "============================================================"
echo " 🚀 UNRAID REBOOT SEQUENCE STARTING"
echo "------------------------------------------------------------"
echo " ⏱ Delay: ${REBOOT_SLEEP}s"
echo " 🧪 Dry Run: $DRY_RUN"
echo "============================================================"
log "️ Reboot sequence initiated"
# FUNCTIONS
notify_users() {
warn "🟡 Notifying users of reboot"
wall "⚠️ Unraid server will reboot in ${REBOOT_SLEEP} second(s). Save your work."
}
# --- MAIN
echo "==== Scheduled Reboot Script Started: $(date) ===="
stop_docker() {
if [[ "$DRY_RUN" == true ]]; then
warn "🧪 Would stop Docker service"
return
fi
# Optional warning before reboot
if [ "$REBOOT_SLEEP" -gt 0 ]; then
notify_users
sleep "$REBOOT_SLEEP"
info "🟡 Stopping Docker service"
if /etc/rc.d/rc.docker stop; then
info "🟢 Docker stopped"
else
warn "🔴 Docker stop failed or already stopped"
fi
}
stop_vm_manager() {
if [[ "$DRY_RUN" == true ]]; then
warn "🧪 Would stop VM Manager (libvirt)"
return
fi
fi
info "🟡 Stopping VM Manager"
# Stop Docker
if [ "$DRY_RUN" = true ]; then
echo "[DRY-RUN] Would stop Docker: /etc/rc.d/rc.docker stop"
else
echo "Stopping Docker..."
/etc/rc.d/rc.docker stop
fi
if /etc/rc.d/rc.libvirt stop; then
info "🟢 VM Manager stopped"
else
warn "🔴 VM Manager stop failed or already stopped"
fi
}
# Stop VM Manager
if [ "$DRY_RUN" = true ]; then
echo "[DRY-RUN] Would stop VM Manager: /etc/rc.d/rc.libvirt stop"
else
echo "Stopping VM Manager..."
/etc/rc.d/rc.libvirt stop
fi
sync_disks() {
if [[ "$DRY_RUN" == true ]]; then
warn "🧪 Would sync filesystem buffers"
return
fi
# Sync disks
if [ "$DRY_RUN" = true ]; then
echo "[DRY-RUN] Would sync disks"
else
echo "Syncing disks..."
sync
fi
info "🟡 Syncing disks"
if sync; then
info "🟢 Disk sync complete"
else
warn "🔴 Sync command returned error"
fi
}
reboot_system() {
if [[ "$DRY_RUN" == true ]]; then
warn "🧪 Would reboot system (/sbin/reboot)"
return
fi
info "🔴 Rebooting system NOW"
# Reboot system
if [ "$DRY_RUN" = true ]; then
echo "[DRY-RUN] Would reboot system: /sbin/reboot"
else
echo "Rebooting system..."
/sbin/reboot
fi
}
# EXECUTION
START_TIME=$(date +%s)
if [[ "$REBOOT_SLEEP" -gt 0 ]]; then
notify_users
info "⏱ Waiting ${REBOOT_SLEEP}s before shutdown sequence"
sleep "$REBOOT_SLEEP"
fi
stop_docker
stop_vm_manager
sync_disks
reboot_system
# NOTE: system will not reach here unless dry-run
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# SUMMARY
echo
echo "============================================================"
if [[ "$DRY_RUN" == true ]]; then
echo " 🟡 REBOOT SUMMARY"
echo "------------------------------------------------------------"
echo " ⏱ Delay: ${REBOOT_SLEEP}s"
echo " 📡 Status: 🟡 DRY RUN (no reboot executed)"
else
echo " 🔴 REBOOT SUMMARY"
echo "------------------------------------------------------------"
echo " ⚠️ Status: 🔴 SYSTEM SHOULD BE REBOOTING"
echo " ⏱ Duration: ${DURATION}s"
fi
echo "============================================================"
info "️ Reboot sequence complete (or handed off to system reboot)"