[mythtv-users] Shutdown unused slaves
John Armstrong
ja at ggrove.plus.com
Wed Mar 22 22:53:18 UTC 2006
From: "Bob" <spam at homeurl.co.uk>
> The best solution would be to have the master consider the shutdown
> slave as "sleeping" and not alter the schedule, in an ideal world, with
> a situation like this the master would start it's 8pm recording as
> normal, at 8:55 it should WOLup the slave and then if at 8:58pm the
> slave isn't available to start it's recording the master would ditch and
> delete it's 8 -> 10pm recording and start the 9 -> 10pm one.
>
> This way you get to keep the current functionality but gain the ability
> to shutdown slaves when they're not needed.
>
> It's all beyond my programming skill though but if you're after testers,
> I'm your man.
A proper solution isn't something I could do either. My simple script is
below, and seems to work ok, with the caveat that the recording schedule may
change as mentioned.
The script runs as a cron job, I'm running it every 10 minutes.
Basic process, is to do a series of checks, and if they all pass, use ssh to
connect to the master backend and queue an at job to send a WOL signal to
the slave. I have ssh setup with private keys, so it can connect without
asking for a password.
It pulls the current backend status and upcoming recordings from the backend
http port. I thought this could be pulled from the database, but couldn't
see the recording schedule. Is it just in memory on the backend?
It won't shut down if the frontend is running, I currently have to exit to
mythwelcome when not in use. I might try and probe the frontend via its
telnet port, and allow a shutdown if it is idle. eg if the frontend has been
showing the main menu for three checks in a row it is idle.
The system load is checked by adding together the 1, 5 and 15 minute load
averages after removing the decimal point. Might need a lower maxidleload on
a more powerful system.
The various echo lines could be removed, they're just for troubleshooting
what is keeping the system awake.
#!/bin/bash
backendhost=backend
maxidleload=30
myencoder=2
maxwaittime=60
warmuptime=5
mymacaddr=12:34:56:78:9A:BC
#################################
#### Check if frontend running
#################################
if ps -e|grep mythfrontend>/dev/null
then
echo "Frontend running"
exit
fi
#################################
#### Check system load isn't high
#################################
set `uptime|sed "s/^.*average://;s/,//g;s/\.//g"`
load=$(( 10#$1 + 10#$2 + 10#$3 ))
if [ $load -gt $maxidleload ]
then
echo "High load $load"
exit
else
echo "Low load $load"
fi
#################################
#### Check not currently recording
#################################
wget -q $backendhost:6544 -O /tmp/backendstatus
if cat /tmp/backendstatus|sed "1,/Encoder status/d;/<h2>Schedule/,$ d"|grep
"Encoder "$myencoder|grep "is recording">/dev/null
then
echo "Recording"
exit
else
echo "Not Recording"
fi
#################################
#### Get time of next recording
#################################
nextrecording=`cat /tmp/backendstatus|sed "1,/<div id=\"schedule\">/d"|grep
"\- Encoder $myencoder \-"|head -n 1|sed "s/^.*This recording will start in
//;s/ using encoder $myencoder .*//;s/ days/ *24*60/;s/ hours*/
*60/;s/and/+/;s/minutes//"`
waittime=$(( $nextrecording ))
echo $waittime
if [ $waittime -lt $maxwaittime ]
then
echo "Less than $maxwaittime minutes wait, $waittime"
else
echo "Long wait $waittime minutes"
wakeup=$(( $waittime - $warmuptime ))
echo "Wake up at now + $wakeup minutes"
echo "/usr/sbin/ether-wake $mymacaddr"|ssh backend at now + $wakeup
minutes
/sbin/shutdown -h now
fi
More information about the mythtv-users
mailing list