MythTV Powersaving

After been using MythTV for several years, I’m now looking for many different tunes etc – for saving power, use different remotes etc. So this is a little site to test all these small tweaks etc I’ve done through the time! After using many different setups I’m ended up with a system where I want access to all the time – No matter what – So what to do.

At this point I’ve fixed the following in my setup:

  • Using less power by shuttingdown the MasterBackend.- OK
  • Waking the MasterBackend up – when needed – OK
  • Setting Wakeup time through Webinterface.

Since I’m using Dell PowerEdge (at the moment) for MBE – I cannot use the rtf for waking up the MasterBackend, since in my Dell – its only possible to use this feature within 24hours – so instead I did this:

Powersave on MasterBackEnd:

In mythtv-setup –> General settings, we need to set these settings under wake up :

  • Block shutdown before client connected : unchecked
  • Idle shutdown timeout (secs) : 1200 –> (20min)
  • Max. wait for recording (min) : 120
  • Startup before rec. (secs) : 600 –> (10min)
  • Wakeup time format : time_t
  • Command to set Wakeup Time : sudo su -c “/storage/scripts/backends/ $time_t”
  • Server halt command :sudo /sbin/shutdown -h now
  • Pre Shutdown check-command : (empty)

For this to work we’ll need the script called /storage/scripts/backends/ :

echo $2 > /tmp/wakeup.txt 
echo "shutdown from mythtv will wake up at $@" >> /var/log/mythtv/mythbackend.[0-9].[0-9].log 
scp /tmp/wakeup.txt root@

This script takes the wakeup time and put it into /tmp/wakeup.txt – and put it on our little wakeupmachine( evt. Router if running Linux) . Afterwards it’ll shutdown the MasterBackEnd (It self) and wait for a WOL package to wake it up.

On the other host:

Using crontab on this host – We’ll check /tmp/wakeup.txt for the time in there – so the script checks each 2 minute. The script is /scripts/

now11=`date  "+%Y%m%d%H%M"`  
echo "checking for wake up at $now11" > /tmp/wakeup.log  
#now11=`date  "+%s"`  
if [ ! -f /tmp/wakeup.txt ]  
read wakeupat < /tmp/wakeup.txt  
if [ "$wakeupat" -lt "$now11" ]  
     then    /usr/bin/    
     rm /tmp/wakeup.txt    
     echo "woke up mythtv $now11" >> /tmp/wakeup.log  

If the time match – it called the next script /usr/bin/

wakeonlan b8:ac:6f:82:d2:73

Which send the WOLpackage and wake up the MasterBackEnd Server.


Using NFS shares from MasterBackEnd on the Frontends using powersaving:

This is only need if running a symlike system – with NFS-shares on the MBE, and using Powersaving like mine. This means the frontends are powered on – and sending the WOL package to the MBE using a init.d script – this normally means the FE are up and ready before the MBE are ready -. so the drives don’t get mounted (if using fstab) – So instead I did this:

on the Frontend created a script – /etc/init.d/wol

#! /bin/sh 
# Provides:          WOL Mythbackend 
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs 
# Should-Start:      network 
# Should-Stop:       network 
# Default-Start:     2 3 4 5 
# Default-Stop:      0 1 6 
# Short-Description: Start/Stop WOL-package to MBE 
 ### END INIT INFO NAME="Wake Backendserver" 
 DESC="Waking up MBE using Wakeonlan" 
 # MAC address of backend 
 case "$1" in
 # Issue wakeonlan at intervals until our own network interface     
 #  is active and the magic packet is successfully sent.     
 until /usr/bin/wakeonlan $SERVER_MAC > /dev/null 2>&1 ; do       
 sleep 1
 exit 0

and add it for boot time :

chmod +x /etc/init.d/wol
update-rc.d wol defaults 35 20

Since I’m using fluxbox as desktop – I added a few lines in /home/myth/.fluxbox/startup:

 # fluxbox startup-script: # 
 # Lines starting with a '#' are ignored. 
 # Change your keymap: 
 xmodmap "/home/myth/.Xmodmap" 
 # Applications you want to run with fluxbox. 
 # unclutter -idle 2 & 
 # wmnd & 
 # wmsmixer -w & 
 # idesk & # 
 # Debian-local change: 
 #   - fbautostart has been added with a quick hack to check to see if it 
 #     exists. If it does, we'll start it up by default. 
 which fbautostart > /dev/null 
 if [ $? -eq 0 ]; then     
 # And last but not least we start fluxbox. 
 # Because it is the last app you have to run it with ''exec'' before it. 
 /usr/bin/ &
  exec fluxbox 
 # or if you want to keep a log: 
 # exec fluxbox -log "/home/myth/.fluxbox/log"

And then in the last point – we’re starting /usr/bin/

#! /bin/bash 
# IP address of backend 
# SERVER_MAC=xx:xx:xx:xx:xx:xx 
# Could optionally send a wakeup packet here, if 
#  a) it is decided that the early-running script above is not needed, or 
#  b) to cover the rare case that backend was shutting down when first one sent 
# Use mythTV status port as backend connectivity 
test until [ -n "`telnet $SERVER_IP 6544 |grep -i connected`" ]; do
   sleep 3
# remove old logfiles 
rm -rf /var/log/mythtv/* 
# Mounting the different directories 
sudo sh -c "/bin/mount -t nfs /storage/data" 
sudo sh -c "/bin/mount -t nfs /storage/music" 
sudo sh -c "/bin/mount -t nfs /storage/pictures" 
sudo sh -c "/bin/mount -t nfs /storage/records" 
sudo sh -c "/bin/mount -t nfs /storage/movies" 
sudo sh -c "/bin/mount -t nfs /storage/scripts"
# Start mythfrontend 
mythfrontend  --logpath /var/log/mythtv --verbose general --loglevel info --nodblog & 
exit 0

Then make sure that fluxboxare your primary desktop. I needed to logout and then choose fluxbox (between fluxbox,gnome,gnomedesktop). But thenit’ll actually wait until the MasterBackEnd is up and running- before it’ll try mount the NFS shares from MBE, and first then start mythfrontend – if needed without the different params for logging.

But that’s whats working for me(and the kids) and that makes me happy 🙂