Files
Varaverk/unRAID Essentials/server-reboot.sh
T

80 lines
2.3 KiB
Bash

#!/bin/bash
#-----------------------------------------------------------------------------------------------
# ---------------------------- Unattended Reboot Script for Unraid -----------------------------
#-----------------------------------------------------------------------------------------------
#----------------- User Variables, Please adjust in Master.conf as needed ----------------------
#-----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
# Scripts now just contain runtime logic
#
# This new setup allows for profiles and arguments to use the core script
# Use arguments in unRAID User Plugin for directory
# Example: /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
#-----------------------------------------------------------------------------------------------
#---------------End Of User Variables, Please adjust in Master.conf as needed ------------------
#-----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common.sh"
# Load central config
load_master_conf
# Parse CLI args (flags + VAR=value)
parse_args "$@"
# Validate REBOOT_SLEEP
validate_int REBOOT_SLEEP "$REBOOT_SLEEP"
# --- Functions
notify_users() {
wall "⚠️ Unraid server will reboot in ${REBOOT_SLEEP} second(s). Save your work."
}
# --- MAIN
echo "==== Scheduled Reboot Script Started: $(date) ===="
# Optional warning before reboot
if [ "$REBOOT_SLEEP" -gt 0 ]; then
notify_users
sleep "$REBOOT_SLEEP"
fi
# 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
# 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
echo "[DRY-RUN] Would sync disks"
else
echo "Syncing disks..."
sync
fi
# Reboot system
if [ "$DRY_RUN" = true ]; then
echo "[DRY-RUN] Would reboot system: /sbin/reboot"
else
echo "Rebooting system..."
/sbin/reboot
fi