Shutdown.sh

Aus VDR Wiki
(Unterschied zwischen Versionen)
Wechseln zu: Navigation, Suche
K (Kategorie)
 
(12 dazwischenliegende Versionen von 8 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
{{übersetzen|10}}
 
 
==Beschreibung==
 
Aus '''INSTALL''' (VDR).
 
 
<pre>
 
Automatic shutdown:
 
-------------------
 
 
If you define a shutdown command via the '-s' command line option, VDR
 
will call the given command if there is currently no recording or replay
 
active, the user has been inactive for at least MinUserInactivity minutes
 
and the next timer event is at least MinEventTimeout minutes in the future
 
(see the Setup parameters in MANUAL).
 
 
The command given in the '-s' option will be called with five parameters.
 
The first one is the time (in UTC) of the next timer event (as a time_t
 
type number), and the second one is the number of seconds from the current
 
time until the next timer event. Your program can choose which one to use
 
for programming some sort of hardware device that makes sure the computer
 
will be restarted in time before the next timer event. Your program must
 
also initiate the actual shutdown procedure of the computer. After this
 
your program should return to VDR. VDR will not automatically exit after
 
calling the shutdown program, but will rather continue normally until it
 
receives a SIGTERM when the computer is actually shut down. So in case
 
the shutdown fails, or the shutdown program for some reason decides not to
 
perform a shutdown, VDR will stay up and running and will call the shutdown
 
program again after another MinUserInactivity minutes.
 
 
If there are currently no timers active, both parameters will be '0'.
 
In that case the program shall not set the hardware for automatic restart
 
and only perform the system shutdown. A program that uses the second parameter
 
to set the hardware for restart must therefore also check whether the first
 
parameter is '0'.
 
 
The third parameter contains the number of the channel that will be recorded
 
by the next timer (or 0 if no timer is present), and the fourth parameter
 
contains the file name of the recording as defined in the timer (or an empty
 
string if no timer is present). These can be used by the shutdown program to
 
show that information on some display interface etc.
 
 
The fifth parameter indicates the reason why the shutdown was requested.
 
'0' means this is an automatic shutdown due to some timeout, while '1' means
 
that this is a user requested shutdown (resulting from pressing the "Power"
 
key). The shutdown program may use this information to decide whether or
 
not to actually perform the system shutdown.
 
 
If a timer is currently recording, the parameters will reflect the start
 
time of that timer. This means that the first parameter will be a time in
 
the past, and the second parameter will be a negative number. This only
 
happens if the user presses the "Power" key while a timer is currently
 
recording.
 
 
Before the shutdown program is called, the user will be prompted to inform
 
him that the system is about to shut down. If any remote control key is
 
pressed while this prompt is visible, the shutdown will be cancelled (and
 
tried again after another MinUserInactivity minutes). The shutdown prompt
 
will be displayed for 5 minutes, which should be enough time for the user
 
to react.
 
 
A sample shell script to be used with the '-s' option might look like this:
 
 
#!/bin/sh
 
setRTCwakeup $(($1 - 300))
 
sudo halt
 
 
Here 'setRTCwakeup' would be some program that uses the first parameter
 
(which is the absolute time of the next timer event) to set the Real Time
 
Clock so that it wakes up the computer 5 minutes (i.e. 300 seconds) before
 
that event. The 'sudo halt' command then shuts down the computer.
 
You will have to substitute both commands with whatever applies to your
 
particular hard- and software environment.
 
 
If the '-s' option is present, the VDR machine can be turned off by pressing
 
the "Power" key on the remote control.
 
</pre>
 
 
==Beispiel==
 
 
Vorschlag für ein einfaches Shutdown-Skript.
 
Vorschlag für ein einfaches Shutdown-Skript.
  
Übergabe.
+
==Übergabe==
 
+
 
  -s [[Struktur|$PATH]]/shutdown.sh
 
  -s [[Struktur|$PATH]]/shutdown.sh
 
  --shutdown=[[Struktur|$PATH]]/shutdown.sh
 
  --shutdown=[[Struktur|$PATH]]/shutdown.sh
Zeile 86: Zeile 7:
 
Siehe auch [[VDR Optionen]].
 
Siehe auch [[VDR Optionen]].
  
Quellen:
+
==shutdown.sh==
 
+
* ''shutdown.sh'' [[NVRAM WakeUp]]
+
* [http://www.hubertus-sandmann.homepage.t-online.de/vdr_wakeup.htm Hubertus Sandmann]
+
 
+
 
+
 
{{Box Datei | [[Struktur|$PATH]]/shutdown.sh |
 
{{Box Datei | [[Struktur|$PATH]]/shutdown.sh |
 
<pre>
 
<pre>
Zeile 122: Zeile 38:
 
test -e $ACPIALARM
 
test -e $ACPIALARM
 
case $? in
 
case $? in
    0) date -d "1970-01-01 UTC $((TIMER-120)) seconds" +"%Y-%m-%d %R:%S" > $ACPIALARM
+
    0) date -d "1970-01-01 UTC $(($TIMER-120)) seconds" +"%Y-%m-%d %R:%S" > $ACPIALARM
 
sudo poweroff
 
sudo poweroff
 
exit 0
 
exit 0
Zeile 131: Zeile 47:
 
;;
 
;;
 
     10-nvram)
 
     10-nvram)
test -e /dev/nvram -a -e /dev/rtc -a -e /dev/mem
+
eval test $(echo $NVRAM_OPT | egrep -q directisa || echo "-e /dev/nvram -a") -e /dev/rtc -a -e /dev/mem
 
case $? in
 
case $? in
 
    0) which nvram-wakeup >/dev/null 2>&1
 
    0) which nvram-wakeup >/dev/null 2>&1
Zeile 139: Zeile 55:
 
    grub) REBOOT_LINE=`grep -s ^title "$GRUBCNF" | grep -i -n poweroff | { IFS=: read a b ; echo $a ; }`
 
    grub) REBOOT_LINE=`grep -s ^title "$GRUBCNF" | grep -i -n poweroff | { IFS=: read a b ; echo $a ; }`
 
  test -n "$REBOOT_LINE"
 
  test -n "$REBOOT_LINE"
  case $? in
+
                                  case $? in
 
0) which grub-set-default >/dev/null 2>&1
 
0) which grub-set-default >/dev/null 2>&1
 
  case $? in
 
  case $? in
0) sudo grub-set-default $((REBOOT_LINE-1))
+
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
 
*) echo -e "savedefault --default=$((REBOOT_LINE-1)) --once\nquit" | sudo grub --batch
Zeile 169: Zeile 91:
 
esac
 
esac
 
;;
 
;;
    *) logger -t ${0##*/} "ARG -> missing /dev/nvram -o /dev/rtc -o /dev/mem"
+
    *) logger -t ${0##*/} "ARG -> missing $(echo $NVRAM_OPT | egrep -q directisa || echo /dev/nvram -o) /dev/rtc -o /dev/mem"
 
;;
 
;;
 
esac
 
esac
Zeile 198: Zeile 120:
 
}}
 
}}
  
==[[NVRAM WakeUp]]==
+
==[[NVRAM WakeUp]] (''reboot-kernel'')==
 
  shell> cd /tmp
 
  shell> cd /tmp
  shell> cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/nvram-wakeup login
+
  shell> cvs -d:pserver:anonymous@nvram-wakeup.cvs.sourceforge.net:/cvsroot/nvram-wakeup login
  shell> cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/nvram-wakeup co nvram-wakeup/reboot
+
  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.
 
Hier sollte sich ein passender ''Reboot-Kernel'' finden, welcher nach '''/boot''' verfrachtet wird.
Zeile 242: Zeile 164:
 
  # Added pluto *
 
  # Added pluto *
 
  # Added PowerOff
 
  # 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.<br/>
 +
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==
 +
* ''shutdown.sh'' [[NVRAM WakeUp]]
 +
* [http://www.hubertus-sandmann.homepage.t-online.de/vdr_wakeup.htm Hubertus Sandmann]
  
 
[[Kategorie:Skripte]]
 
[[Kategorie:Skripte]]
 +
[[Kategorie:Wakeup]]

Aktuelle Version vom 6. Dezember 2008, 23:24 Uhr

Vorschlag für ein einfaches Shutdown-Skript.

Inhaltsverzeichnis

[Bearbeiten] Übergabe

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

Siehe auch VDR Optionen.

[Bearbeiten] 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 $?


[Bearbeiten] 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 \;

[Bearbeiten] Ergänzung für GRUB

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


[Bearbeiten] 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.)

[Bearbeiten] Quellen