Wakeup » History » Version 1
ruud -, 2011-02-11 19:36
1 | 1 | ruud - | h1. HowTo wakeup XBMC/TVHeadend for scheduled recording. |
---|---|---|---|
2 | |||
3 | 1. Make sure you motherboard supports ACPI Wakeup |
||
4 | Look at the nice MythTV-Wiki page: http://www.mythtv.org/wiki/ACPI_Wakeup for detailed description. |
||
5 | |||
6 | 2. Make sure you have correctly working suspend script. In my case it was important to suspend system |
||
7 | - not to shutdown it. Please check suspend state your system (BIOS) is able to wakeup from: |
||
8 | |||
9 | <pre> |
||
10 | $ grep -i rtc /var/log/kern.log |
||
11 | RTC can wake from S4 |
||
12 | ... |
||
13 | rtc0: alarms up to one month |
||
14 | </pre> |
||
15 | |||
16 | 3. Check if all your hardware drivers support suspend (means can easly wakeup from suspend). |
||
17 | If some of them not, you should remove them before suspend and load them again after wakeup. |
||
18 | Here is example I use (/etc/pm/sleep.d/99_htpc.sh): |
||
19 | |||
20 | <pre> |
||
21 | #!/bin/sh |
||
22 | |||
23 | # This script uses curl. Install curl using the following command from your terminal apt-get install curl |
||
24 | # This script will restart lirc drivers, Lirc, and XBMC's lirc interperater upon resume. |
||
25 | |||
26 | case "$1" in |
||
27 | suspend|hibernate) |
||
28 | service xbmc-live stop |
||
29 | /etc/init.d/tvheadend stop |
||
30 | /etc/init.d/lirc stop |
||
31 | rmmod mantis |
||
32 | rmmod ivtv |
||
33 | rmmod nvidia |
||
34 | ;; |
||
35 | resume|thaw) |
||
36 | modprobe nvidia |
||
37 | modprobe mantis |
||
38 | modprobe ivtv |
||
39 | sleep 1 |
||
40 | /etc/init.d/lirc start |
||
41 | /etc/init.d/tvheadend start |
||
42 | #remove the comment if the computer automatically sleeps after resume |
||
43 | #irw & sleep 1; killall irw |
||
44 | sleep 2 |
||
45 | service xbmc-live start |
||
46 | ;; |
||
47 | esac |
||
48 | </pre> |
||
49 | |||
50 | 4. Create new script (the same path i.e. /etc/pm/sleep.d/95_timer.sh) to check if there is |
||
51 | new upcoming recording event. Script checks also the earliest event's date. Modify "safe_margin" |
||
52 | variable to be sure system will be ready before recording will start. |
||
53 | |||
54 | <pre> |
||
55 | #!/bin/bash |
||
56 | # |
||
57 | # set ACPI Wakeup alarm |
||
58 | # safe_margin - minutes to start up system before the earliest timer |
||
59 | # script does not check if recording is in progress |
||
60 | # |
||
61 | # |
||
62 | |||
63 | echo 1 > /timer |
||
64 | |||
65 | # bootup system 60 sec. before timer |
||
66 | safe_margin=60 |
||
67 | |||
68 | # modyfy if different location for tvheadend dvr/log path |
||
69 | cd ~hts/.hts/tvheadend/dvr/log |
||
70 | |||
71 | ###################### |
||
72 | |||
73 | start_date=0 |
||
74 | stop_date=0 |
||
75 | |||
76 | current_date=`date +%s` |
||
77 | |||
78 | for i in $( ls ); do |
||
79 | tmp_start=`cat $i | grep '"start":' | cut -f 2 -d " " | cut -f 1 -d ","` |
||
80 | tmp_stop=`cat $i | grep '"stop":' | cut -f 2 -d " " | cut -f 1 -d ","` |
||
81 | |||
82 | # check for outdated timer |
||
83 | if [ $((tmp_stop)) -gt $((current_date)) -a $((tmp_start)) -gt $((current_date)) ]; then |
||
84 | |||
85 | # take lower value (tmp_start or start_date) |
||
86 | if [ $((start_date)) -eq 0 -o $((tmp_start)) -lt $((start_date)) ]; then |
||
87 | start_date=$tmp_start |
||
88 | stop_date=$tmp_stop |
||
89 | fi |
||
90 | fi |
||
91 | done |
||
92 | |||
93 | wake_date=$((start_date-safe_margin)) |
||
94 | |||
95 | echo $start_date >> /timer |
||
96 | echo $wake_date >> /timer |
||
97 | |||
98 | # set up waleup alarm |
||
99 | if [ $((start_date)) -ne 0 ]; then |
||
100 | echo 2 >> /timer |
||
101 | echo 0 > /sys/class/rtc/rtc0/wakealarm |
||
102 | echo $wake_date > /sys/class/rtc/rtc0/wakealarm |
||
103 | fi |
||
104 | </pre> |
||
105 | |||
106 | h1. Shutdown (suspend) system after recording |
||
107 | |||
108 | To shutdown (suspend) system after recording you can do a quick trick: |
||
109 | |||
110 | 1. Check what system user is your tvheadend run on. In my case: hts |
||
111 | 2. Create a simple script somewhere i.e. /home/hts/shutdown.sh |
||
112 | as follows (remember to make it executable: chmod u+x): |
||
113 | |||
114 | <pre> |
||
115 | #!/bin/sh |
||
116 | |||
117 | # Here you can invoke your script for recording's post-processing |
||
118 | #exec <your_script.sh> |
||
119 | |||
120 | sleep 20 |
||
121 | sudo /usr/sbin/pm-suspend & |
||
122 | </pre> |
||
123 | |||
124 | 3. Make sure your system user tvheadend is running on have enough priviligdes to suspend system: |
||
125 | add following line to /etc/sudoers (repleace 'hts' with user your tvheadend is run on): |
||
126 | |||
127 | <pre> |
||
128 | hts ALL=NOPASSWD: /usr/sbin/pm-suspend # TVHeadend |
||
129 | </pre> |
||
130 | |||
131 | 4. Through the web page of tvheadend: Configuration -> Digital Video Recorder |
||
132 | point parameter 'Post-processor command' to your script i.e. /home/hts/shutdown.sh |