Shutdown.sh

Aus VDR Wiki
Wechseln zu: Navigation, Suche

Vorschlag für ein einfaches Shutdown-Skript.

Inhaltsverzeichnis

Übergabe

-s $PATH/shutdown.sh
--shutdown=$PATH/shutdown.sh

Siehe auch VDR Optionen.

shutdown.sh

Datei
$PATH/shutdown.sh
#!/bin/bash
#
# shutdown.sh

# wake up method ('off','acpi','nvram','suspend')
WAKEUP_METHOD="off"

# read board configuration from specified configuration file (e.g: "/etc/nvram-wakeup.conf")
NVRAM_CONFIG=""

# specify the iw (infowriter) name. (e.g: gigabyte_5aa)
NVRAM_IWNAME=""

# try "nvram-wakeup --help"
NVRAM_OPT="--syslog"

# Which boot manager are you using? (grub/lilo)
BOOT_MANAGER="grub"

TIMER=$1
LILOCNF=/etc/lilo.conf
GRUBCNF=/boot/grub/menu.lst
ACPIALARM=/proc/acpi/alarm

case ${#TIMER}-${WAKEUP_METHOD:-off} in
     10-acpi)
	test -e $ACPIALARM
	case $? in
	     0) date -d "1970-01-01 UTC $(($TIMER-120)) seconds" +"%Y-%m-%d %R:%S" > $ACPIALARM
		sudo poweroff
		exit 0
		;;
	     *) logger -t ${0##*/} "ARG -> missing $ACPIALARM"
		;;
	esac
	;;
     10-nvram)
	eval test $(echo $NVRAM_OPT | egrep -q directisa || echo "-e /dev/nvram -a") -e /dev/rtc -a -e /dev/mem
	case $? in
	     0) which nvram-wakeup >/dev/null 2>&1
		case $? in
		     0) sudo nvram-wakeup -s $TIMER $NVRAM_OPT ${NVRAM_CONFIG:+-C $NVRAM_CONFIG} ${NVRAM_IWNAME:+-I $NVRAM_IWNAME}
			case ${BOOT_MANAGER:-lilo} in
			     grub) REBOOT_LINE=`grep -s ^title "$GRUBCNF" | grep -i -n poweroff | { IFS=: read a b ; echo $a ; }`
				   test -n "$REBOOT_LINE"
                                   case $? in
					0) which grub-set-default >/dev/null 2>&1
					   case $? in
						0) which grubonce >/dev/null 2>&1
						   case $? in
						        0) sudo grubonce $((REBOOT_LINE-1))
							   ;;
							*) sudo grub-set-default $((REBOOT_LINE-1))
							   ;;
						   esac
						   ;;
						*) echo -e "savedefault --default=$((REBOOT_LINE-1)) --once\nquit" | sudo grub --batch
						   ;;
					   esac
					   ;;
					*) logger -t ${0##*/} "ARG -> missing poweroff entry in $GRUBCNF"
					   ;;
				   esac
				   ;;
			     lilo) REBOOT_ENTRY=`grep -s -i label.*poweroff "$LILOCNF" | { IFS== read a b ; echo $b ; }`
				   test -n "$REBOOT_ENTRY"
				   case $? in
					0) sudo lilo -R $REBOOT_ENTRY
					   ;;
					*) logger -t ${0##*/} "ARG -> missing poweroff entry in $LILOCNF"
					   ;;
				   esac
				   ;;
			esac
			sudo shutdown -r now
			exit 0
			;;
		     *) logger -t ${0##*/} "ARG -> missing nvram-wakeup"
			;;
		esac
		;;
	     *) logger -t ${0##*/} "ARG -> missing $(echo $NVRAM_OPT | egrep -q directisa || echo /dev/nvram -o) /dev/rtc -o /dev/mem"
		;;
	esac
	;;
     10-suspend)
	test -e $ACPIALARM -a -e /sys/power/state
	case $? in
	     0) date -d "1970-01-01 UTC $((TIMER-120)) seconds" +"%Y-%m-%d %R:%S" > $ACPIALARM
		echo mem > /sys/power/state
		sudo reboot
		exit 0
		;;
	     *) logger -t ${0##*/} "ARG -> missing $ACPIALARM -o /sys/power/state"
		;;
	esac
	;;
     10-off)
	logger -t ${0##*/} "MESG -> no wakeup method"
	;;
     1-*)
	logger -t ${0##*/} "MESG -> no timer"
	;;
esac

sudo shutdown -h now
exit $?


NVRAM WakeUp (reboot-kernel)

shell> cd /tmp
shell> cvs -d:pserver:anonymous@nvram-wakeup.cvs.sourceforge.net:/cvsroot/nvram-wakeup login
shell> cvs -d:pserver:anonymous@nvram-wakeup.cvs.sourceforge.net:/cvsroot/nvram-wakeup co nvram-wakeup/reboot

Hier sollte sich ein passender Reboot-Kernel finden, welcher nach /boot verfrachtet wird.

shell> KERNEL_VERSION=`uname -r`
shell> find $PWD -name "bzImage.${KERNEL_VERSION:0:3}*" -exec cp -v {} /boot/bzImage.poweroff \;

Ergänzung für GRUB

Datei
/boot/grub/menu.lst
...
title           PowerOff
root            (hd0,0)
kernel          /boot/bzImage.poweroff


Ergänzung für LILO

Datei
/etc/lilo.conf
...
label  = PowerOff
image  = /boot/bzImage.poweroff


Oder.

Datei
/etc/lilo.conf
...
image  = /boot/bzImage.poweroff
label  = PowerOff


Dannach LILO aufrufen.

shell> lilo
# Added pluto *
# Added PowerOff

Sollte bei der Ausführung von lilo -R innerhalb eines Shutdown-Skriptes oder -Hooks (wie bei Debian üblich) der Fehler "Fatal: chroot /dev/root: Not a directory" auftreten, so muss zusätzlich der Kommandozeilenparameter "-r /" angefügt werden.
Dies wurde bis jetzt nur bei Debian-Systemen beobachtet und trat nur dann auf, wenn das Init-Skript, welches den VDR startet, automatisch beim Systemstart ausgeführt wurde, nicht aber wenn man das Init-Skript aus einer Shell aufruft oder das Shutdown-Skript von Hand startet.

In obigem Skript müsste in diesem Fall die Zeile

sudo lilo -R $REBOOT_ENTRY

durch diese

sudo lilo -r / -R $REBOOT_ENTRY

ersetzt werden.

(lilo -R wurde in den bekannten Fällen nicht per sudo gestartet, möglicherweise tritt das Problem nicht bei der Verwendung von sudo auf.)

Quellen