Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] runvdr in python



I translated runvdr script in python.
I did so because I know python much better than bash and I need
messing often with it.
I added a feature so when vdr crash 3 times in a row (less than 30 sec
between crashes) runvdr quits.
It save me a lot of "killall runvdr" when drivers are broken!

I publish it here in case someone else may find it useful.

-- cut here
#!/usr/bin/python

# runvdr: Loads the DVB driver and runs VDR
#
# If VDR exits abnormally, the driver will be reloaded
# and VDR restarted.
#
# Set the environment variable VDRUSR to the user id you
# want VDR to run with. If VDRUSR is not set, VDR will run
# as 'root', which is not necessarily advisable.
#
# Since this script loads the DVB driver, it must be started
# as user 'root'.
#
# Any command line parameters will be passed on to the
# actual 'vdr' program.
#
# See the main source file 'vdr.c' for copyright information and
# how to reach the author.
#
# Uberto: 
# 18-apr-2003 rewrite runvdr in python from bash script
# 30-apr-2003 print vdr exit value
# 01-may-2003 check and exit if vdr restart 3 times in a row

import os
import popen2
import commands
import time
import string
import sys

dvbdir="/usr/src/DVB/driver"
vdrprg="/usr/src/VDR/vdr"

lsmod="/sbin/lsmod | /usr/bin/grep -w '^dvb' | /usr/bin/wc -l"
killcmd="/bin/killall -q -TERM"

nm = string.strip(commands.getoutput(lsmod))

if (nm == "0"):
   os.system("cd " + dvbdir + "; make insmod")
else:
   print nm

cmd = vdrprg 
cmd += " -L /usr/src/VDR/PLUGINS/lib"
#cmd += " -t /dev/tty8"
cmd += " -P 'dvd -C /dev/hdc'"
cmd += " -P vcd" 
cmd += " -P 'mplayer -m /video/plugins/mount.sh -M /video/plugins/mplayer.sh'"
cmd += " -P 'mp3 -m /video/plugins/mount.sh'"       
cmd += " -P 'image -m /video/plugins/mount.sh -C /video/plugins/convert.sh'"
cmd += " -P games"
cmd += " -P 'osdteletext -r'" 
cmd += " -P clock" 
cmd += " -P prefermenu" 
#cmd += " -P ttxtsubs" 
cmd += " -w 30"
cmd += " -s /root/shutdown"
cmd += " $*" 

print "starting vdr"

rest = 0
t = time.time()
cont = True
while cont:
    r = os.system(cmd)
    if r == 0:
        print "vdr exited gracefully at", time.ctime()
        cont = False
    else:
        print "vdr exited with error =", r
        ot = t
        t = time.time()
        print "seconds since last restart", t-ot
        if t < (ot + 30):
            rest += 1
            print "vdr restarted (try", rest, "/ 3)"
            if rest >= 3:
                print "restarted 3 times in a row, now exit!"
                cont = False
        else:
            rest = 0
        if cont == True:
            print "killing vdr"
            os.system(killcmd + " " + vdrprg)
            time.sleep(5)
            print "reinstalling dvb modules"
            os.system("cd " + dvbdir + "; make rmmod; make insmod")
            print "restarting vdr at", time.ctime()

-- cut here

Ciao Uberto


mailto:uberto@ubiland.net



-- 
Info:
To unsubscribe send a mail to ecartis@linuxtv.org with "unsubscribe vdr" as subject.



Home | Main Index | Thread Index