Forums » Tutorial and setups »
TVheadend: Suspend after recording and honouring (XBMC) clients
Added by Paul Rensel over 13 years ago
Hi,
I just modified the shutdown script as mentioned in the ACPI suspend wiki.
I've noticed the current shutdown script doesnt honour any running recordings or active viewing clients so i modified the script a bit.
Simply put this script is run after a recording has finished and it then checks for any other running recordings and checks for active clients by simply using a ping command. If there's no running recording and no active client(s) the scripts puts the TVHeadend server in suspend mode by issueing ACPI pm-suspend (check the wiki on how this works).
Sending a WOL or having an active ACPI timer entry awakes the server when needed.
#!/bin/bash # # # modyfy if different location for tvheadend dvr/log path cd ~hts/.hts/tvheadend/dvr/log ###################### start_date=0 stop_date=0 recording=0 pingcount=0 # wait for at least 60 seconds to let the calling recording expire sleep 60 current_date=`date +%s` for i in $( ls ); do tmp_start=`cat $i | grep '"start":' | cut -f 2 -d " " | cut -f 1 -d ","` tmp_stop=`cat $i | grep '"stop":' | cut -f 2 -d " " | cut -f 1 -d ","` # check for any current recording if [ $((tmp_stop)) -gt $((current_date)) -a $((tmp_start)) -lt $((current_date)) ]; then recording=1 fi done #if [ $((recording)) -ne 0 ]; then # echo "Recording in progress" #fi # check to see if there's an active client pingcount=$(ping -c1 192.168.1.41 | grep 'received' | awk -F ',' '{print $2}' | awk '{ print $1}') #echo "Pingcount is $pingcount" # do the final check, no pingcount and no recording means we can suspend # if [ $((pingcount)) -eq 0 -a $((recording)) -eq 0 ]; then #echo "XBMC is NOT active and NO recording in progress, so going into SUSPEND" sudo /usr/sbin/pm-suspend fi