Shutdown.sh

Aus VDR Wiki
(Unterschied zwischen Versionen)
Wechseln zu: Navigation, Suche
(M)
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.
  

Version vom 22. April 2006, 16:59 Uhr


Dieser Artikel wurde noch nicht komplett ins Deutsche übersetzt! (Übersetzung zu ~ 10 % durchgeführt.)
Das könntest auch Du machen, einfach per [bearbeiten]. Danach bitte {{übersetzen|<Zahl>}} aus dem Kopf des Artikels entfernen. DANKE :-)


Inhaltsverzeichnis

Beschreibung

Aus INSTALL (VDR).

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.

Beispiel

Vorschlag für ein einfaches Shutdown-Skript.

Übergabe.

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

Siehe auch VDR Optionen.

Quellen:


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)
	test -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) sudo grub-set-default $((REBOOT_LINE-1))
						   ;;
						*) 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 /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

shell> cd /tmp
shell> cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/nvram-wakeup login
shell> cvs -z3 -d:pserver:anonymous@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