This is really for power-saving purposes. Suspend to ram, rather than shutdown/reboot is much faster and makes for a better experience. There are a couple of tricks (waiting for services to terminate and waiting for mythbackend to accept connections) that might be more generally useful.
I have a combined frontend/backend. I'm running an nvidia graphics card, Hauppauge Nova-T 500 tuner and an Imon LCD/IR module (the one that comes with one of the first Antec Fusion Black). I use tools from the pm-utils and net-tools packages.
Graphics Card Setup
See, for instance,
http://en.opensuse.org/NVidia_Suspend_HOWTO. I have
Code:
Option "NvAGP" "1"
in the Device section of /etc/X11/xorg.conf. Also in /etc/modprobe.conf I have
Code:
blacklist intel_agp
pm-utils setupThe pm-utils setup makes sure that everything that can't survive a suspend/resume cycle gets shutdown cleanly before the suspend and brought back up after resume. In my case both the tuner and lirc kernel modules need to be explicitly removed. This means shutting down the lirc, lcdd and mythbackend processes before removing the modules.
Make sure that pm-utils are installed
Code:
sudo pacman -Sy pm-utils
In /etc/pm/config.d/modules
Code:
# Modules that need to be unloaded before suspend
SUSPEND_MODULES="lirc_imon dvb_usb_dib0700"
The existing pm-utils functions take care of properly removing and reinserting these modules.
In /etc/pm/sleep.d/20services (needs to have execute permission set)
Code:
#!/bin/bash
RUNSV_SERVICES="lcdd lircd mythbackend"
suspend_services()
{
for sv in $RUNSV_SERVICES; do
if [ -f /var/service/$sv/supervise/pid ]; then
pid=`cat /var/service/$sv/supervise/pid`
sv down $sv
while kill -0 $pid > /dev/null 2>&1; do sleep 0.1; done
fi
done
}
resume_services()
{
for sv in $RUNSV_SERVICES; do
sv up $sv
done
}
case "$1" in
hibernate|suspend)
suspend_services
;;
thaw|resume)
resume_services
;;
*) exit $NA
;;
esac
Notice that I explicitly wait for each process to shutdown before moving on to the next (although I don't wait for them to start). This ensures that everything's actually stopped before the kernel modules are removed.
After making the graphics card changes and the pm-utils mods a manual call to pm-suspend (after shutting down mythfrontend) should work
Code:
sudo pm-suspend
mythtv setupMain references
http://www.mythtv.org/wiki/index.php/ACPI_Wakeup and
http://www.mythtv.org/wiki/index.php/MythwelcomeIn mythtv-setup Shutdown/Wakeup settings
Code:
Block shutdown before
client connected: checked
Idletimeout (secs): any value greater that 0
Wakeup time format: yyyy-MM-ddThh:mm
Set wakeup time command: mythshutdown --setwakeup $time
Server Halt command: mythshutdown --shutdown
Pre shutdown check command: mythshutdown --check
In mythwelcome --setup
Code:
Command to Set Wakeup Time: /home/mythtv/bin/mythtv-wakeset $time
Wakeup time format: time_t
nvrm-wakeup Restart Command: (blank)
Comand to reboot: sudo /sbin/reboot
Command to shutdown: /home/mythtv/bin/mythtv-suspend
Command to run xterm: /usr/bin/mrxvt
Command to start the frontend: /usr/bin/mythfrontend
mythtv-wakeset looks like this:
Code:
#!/bin/bash
# set mythtv wake-up time with UTC-adjusted time
DATE=`date -d "1970-01-01 $1 sec" "+%F %H:%M:%S" -u`
SECS=`date -d "1970-01-01 $1 sec" "+%s" -u`
# set the alarm
echo "Setting wakeup time."
echo " Date: `date +"%F %T %z"`"
echo " Input: $1"
echo " Adjusted to UTC: $DATE -- $SECS"
sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sudo sh -c "echo $SECS > /sys/class/rtc/rtc0/wakealarm"
echo "Time set."
cat /proc/driver/rtc
and mythtv-syspend looks like this:
Code:
#!/bin/bash
# MythtTV suspend script
# First take down anything mythtfrontend-related
killall mythlcdserver
killall mythwelcome
# Suspend - this takes care of mythbackend
sudo pm-suspend
# Wait for the backend to accept connections
while !(netstat -pl 2>&1 | grep -q mythbackend); do sleep 0.1; done
# Bring up the frontend
export DISPLAY=:0.0
/usr/bin/mythwelcome &
Note the trick to make sure that the backend is up before starting the frontend. This prevents any annoying "Cannot connect to backend" messages. netstat is the program from the net-tools package. I think the package is installed by default.
DebuggingYou'll want to read the references that I've given, the appropriate man pages, plus Google (of course). Start by getting suspend/resume to work (figuring out which kernel modules need to be unloaded is fun), then make sure that the system bios will restart at the time you specify, then bringing mythtv into the mix should be straightforward.
A couple of useful snippets for checking that your motherboard bios is going to do the right thing: Manual test for reboot (as root). This sets the wakeup time 5 mins in the future
Code:
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm
this checks the current bios info
Code:
cat /proc/driver/rtc
Reboot (or suspend) to test.
The End
I think that's it. I'll edit if I remember anything else ...