zondag 6 maart 2011

Sleeping your frontend, for backend power saving

My backend shuts itself down and wakes up on demand. But.. external frontends combined with lazy people, this means the backend remains powered on -doing nothing- every now and then. So I went out to see if I could put the frontends to sleep while also stopping mythfrontend, enabling the backend to start its shutdown sequence. I sleep the machines running the frontends because there may be running browser sessions etc.

How to set it up:

Gnome Power Manager -which is used by Ubuntu- waits until the screensaver says the desktop is idle and then does its own countdown. So the total time until sleep, is the time until the screensaver comes up plus the time you set in Gnome Power Manager. btw, LiveTV automatically disables the screensaver so we have the covered. We won't accidentally stop someone viewing television.

You will need to setup the screensaver and Gnome Power Manager yourself.

Then create a file as root:
$ sudo nano -w /etc/pm/sleep.d/00_quit-mythfrontend


#!/bin/sh
#
# Kill mythfrontend

case "$1" in
hibernate|suspend)
killall mythfrontend.real
killall mythfrontend
sleep 5s
esac

Set it executable:
$ sudo chmod +x /etc/pm/sleep.d/00_quit-mythfrontend


Your frontend will now be stopped before the machine goes to sleep.

Tip: don't name it 99_kill-mythfrontend, then the network will be down before the frontend has finished its exit ceremony.