HD-PVR Power Cycle by Module Reload

From MythTV Official Wiki
Revision as of 16:58, 8 December 2012 by Steveadeff (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Author Steve Adeff
Description A method to power cycle the HD-PVR by reloading the driver module

multi HD-PVR safe module reload script

This is another method of "power-cycling" the HD-PVR for when it fails to properly record. Much like the actions taken by "HD-PVR Killer Device", this attempts to leverage the idea that just reloading the driver modules will achieve the same result.

It is intended that this script be run via the /etc/cron.hourly directory. As such a control allowing you to limit the hours between which the script will run are in place.

This script has some variables at the beginning that the user must set, this includes user and password for your mythweb installation if you have them set.

The other is the above mentioned hour control, MINHR and MAXHR, which are to be set in 24h format (ie 1pm = 13). If you wish to allow it to run at any time setting the values to MINHR=0 and MAXHR=25 should work.

You can also have it log the output to a log file, which is what the first few lines accomplish, which can be commented out for testing on the command line.

The actual module commands are in a second script, to allow for easier testing, but can easily be rolled into the main script. That script is below the script to check the HD-PVR status.

Final word of note, this is set up for an English system so if you are running in another language you will have to modify the commands to account for the language difference.

The Code


Script.png hdpvr_check.sh

#export PATH=/usr/bin
exec >> $logfile 2>&1
echo "Checking PVR status at " `date`

## mythweb url, should work as long as the script is being run on the same 
## system as mythweb and apache

## if your mythweb is password protected enter your username and password here

## to limit the time the script will run, place your hour limits here
## in 24h format (ie 1pm=13)

## don't touch these!
TIME=`date +%H`
TODAY=`date +%F`

## Let's start!
echo "Hour: " $TIME
if [ "$TIME" -ge "$MINHR" -a "$TIME" -lt "$MAXHR" ]
		echo "Clear to run at this time!"

		wget -O - --quiet --user=$MYTHWEBUSER --password=$MYTHWEBPASSWORD $MYTHWEBURL | grep HDPVR | \
		while read line
			device=`echo $line | sed -e 's/.*Encoder \([0-9]\).*/\1/'`
			if `echo $line | grep --quiet 'and is not'`
				echo "HDPVR ${device} is not being used"
				echo "however, HDPVR ${device} is busy, we will wait"
				exit 2

		if [ "$STATUS" -eq "1" ]
			echo "no devices are in use!"
			echo "reloading driver for HDPVR devices..."
			echo "an HDPVR is in use, we won't reload at this time"
	echo "Wrong time! We won't run now..."

this is the code to actually unload and load the driver module


Script.png hdpvr_powercycle.sh

#reloads the hdpvr driver, essentially power cycling the hdpvr devices
exec >> $logfile 2>&1
echo "Reloading PVR driver at " `date`

modprobe -r -v hdpvr
sleep 5s
modprobe -v hdpvr