AW: [vdr] execute command after vdr starts

C.Y.M syphir at syphir.sytes.net
Fri Sep 8 06:15:37 CEST 2006


Udo Richter wrote:
> C.Y.M wrote:
>> Yes, I like the idea of backgrounding VDR using "&" and then using
>> 'wait $PID'.
>>  Is that the method you use?  I've been trying to find the best way to
>> do this.
>>  Could you give me an example? :)
> 
> Something like that. This is a snippet of my overgrown runvdr script:
> 
>   # Run VDR
>   eval "$VDRCMD &"
> 
>   # Remember PID of VDR process
>   PID=$!
> 
>   # Wait for VDR to end or signal to arrive
>   wait $PID
> 
>   # Remember return value of VDR
>   RET=$?
> 
> The reason I do it this way is that I also handle some signals sent to
> runvdr, to terminate or restart on demand.
> If you want to start something in parallel, its probably no big
> difference whether you start your script before or after VDR, as long as
> you background it. You can background within a script like this:
> 
>   {
>     sleep 1s
>     echo -n world
>   } &
>   echo -n "hello "
>   sleep 2s
>   echo .
> 
>> For now, I'm just trying to send a MESG via svdrpsend.pl to VDR so it
>> displays a
>> welcome message after starting up and initializing its plugins.  
> 
> You can wait for the SVDRP socket to accept connections, that would be
> one way to wait for a mainly running VDR.
> 

Thanks a lot Udo. Those examples really helped. Here is what I have done...

BR.




-------------- next part --------------
#!/bin/sh
# insmod modules from current directory without having to install them first
# KERNELVER=`uname -r`
# KERNELDIR="/lib/modules/$KERNELVER/misc"

sync

function DriverLoaded()
{
  grep -qse dvb[-_]core /proc/modules
}

DEVTIMEOUT=10
LOOP=0
case "$1" in
    load)
	if ! DriverLoaded; then
	echo -e "Inserting DVB modules into kernel. \n"
	# STARTTIME=$(date +%s)
	# av7110 based "full featured" cards
	modprobe stv0299
	# saa7146 based siemens/technotrend/hauppauge cards
	modprobe dvb-ttpci
	# wait for udev to create the devices before continuing
	until [ -e /dev/dvb/adapter0/video0 ] || [ $LOOP -eq $DEVTIMEOUT ] ; do
	  sleep 1
	  LOOP=$((LOOP+1))
	done
	if [ $LOOP -eq $DEVTIMEOUT ]; then
	  echo -e "Creation of /dev/dvb/adapter0/video0 has timed out in $DEVTIMEOUT seconds. Check UDEV or rebuild drivers. \n"
	  exit 1
	fi
	# FINISHTIME=$(date +%s)
	# RESULTTIME=$((FINISHTIME - STARTTIME))
	# echo -e "DVB device created in $RESULTTIME second(s). \n"
	if [ -e "/usr/local/bin/loadkeys/av7110_loadkeys" ]; then
	  /usr/local/bin/loadkeys/av7110_loadkeys /usr/local/bin/loadkeys/hauppauge_grey.rc5 > /proc/av7110_ir
	  sleep 1
	fi
	else
	echo -e "DVB Drivers already loaded. \n"
	fi
	;;
    debug)
	if ! DriverLoaded; then
	echo -e "Inserting DVB modules (debug) into kernel. \n"
	# STARTTIME=$(date +%s)
	# av7110 based "full featured" cards
	modprobe stv0299 debug_switch_timing=1
	# saa7146 based siemens/technotrend/hauppauge cards
	modprobe dvb-ttpci debug=247
	until [ -e /dev/dvb/adapter0/video0 ] || [ $LOOP -eq $DEVTIMEOUT ] ; do
	  sleep 1
	  LOOP=$((LOOP+1))
	done
	if [ $LOOP -eq $DEVTIMEOUT ]; then
	  echo -e "Creation of /dev/dvb/adapter0/video0 has timed out in $DEVTIMEOUT seconds. Check UDEV or rebuild drivers. \n"
	  exit 1
	fi
	# FINISHTIME=$(date +%s)
	# RESULTTIME=$((FINISHTIME - STARTTIME))
	# echo -e "DVB device created in $RESULTTIME second(s). \n"
	if [ -e "/usr/local/bin/loadkeys/av7110_loadkeys" ]; then
	  /usr/local/bin/loadkeys/av7110_loadkeys /usr/local/bin/loadkeys/hauppauge_grey.rc5 > /proc/av7110_ir
	  sleep 1
	fi
	else
	echo -e "DVB Drivers already loaded. \n"
	fi
	;;
    unload)
	if DriverLoaded; then
	echo -e "Removing DVB modules from kernel. \n"
	rmmod ves1x93 dvb_ttpci saa7146_vv video_buf saa7146 videodev v4l1_compat \
		v4l2_common ttpci_eeprom stv0299 dvb_core
	echo
	else
	echo -e "DVB Drivers not loaded. \n"
	fi
	;;
    reload)
	$0 unload && $0 load
	;;
    *)
	echo "Usage$0 {load|unload|debug|reload}"
	exit 1
esac

sync
-------------- next part --------------
#!/bin/sh

# runvdr: Loads the DVB driver and runs VDR
#
# If VDR exits abnormally, the driver will be reloaded
# and VDR restarted.
#
# In order to actually use this script you need to implement
# the functions DriverLoaded(), LoadDriver() and UnloadDriver()
# and maybe adjust the VDRPRG and VDRCMD to your particular
# requirements.
#
# Since this script loads the DVB driver, it must be started
# as user 'root'. Add the option "-u username" to run VDR
# under the given user name.
#
# 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.
#
# $Id: runvdr 1.19 2006/05/14 16:02:05 kls Exp $

## Start Configuration Section ##

# Disable NPTL (recommended)
export LD_ASSUME_KERNEL=2.4.1
#export LD_ASSUME_KERNEL=2.4.19

# Uncomment to disable UTF-8 within VDR
#export LANG=en_US
#export LC_CTYPE=iso_8859_1

PLUGINS="-Premote -Pscreenshot -Pepgsearch -Pprefermenu -Pdvdselect -Pvcd -Pfemon -Ptaste -Pstreamdev-server -Pstreamplayer -Ptext2skin -Pyaepg -Pundelete -Pweatherng -Posdpip -Pmplayercluster -Peggtimer -Psysinfo -Pradioinfo -P'mp3 -C /etc/vdr -m /etc/vdr/plugins/mount.sh -i /etc/vdr/plugins/image_convert.sh -c /etc/vdr/images' -P'dvd -C/dev/cdrom' -P'mplayer -M /etc/vdr/plugins/mplayer.sh -m /etc/vdr/plugins/mount.sh' -P'xine -r -X 720 -Y 480'"

# VDR Recording directory (default is usually /video)
VIDEO_DIR="/video"
# VDR Configuration directory where setup.conf lives
CFG_DIR="/etc/vdr"
# Where the VDR epg.data file lives
EPG_DIR="/etc/vdr"
# Search path for VDR plugins
PLUG_DIR="/usr/local/bin/PLUGINS/lib"
# Startup Options passed to VDR
OPTIONS="--terminal=/dev/tty8 -l 3 -w 0 --grab=/tmp"
# Path to VDR binary
VDRPRG="/usr/local/bin/vdr"
# Path to insdvb.sh (for loading dvb modules)
INSDVB="/usr/local/bin/insdvb.sh"
# Path to svdrpsend.pl
SVDRP="/usr/local/bin/svdrpsend.pl"
# Path to mplayer
MPLAY="/usr/bin/mplayer"
# Path to startup video
VIDEO="/etc/vdr/VDRboot-NTSC.mpeg"
# Number of times runvdr will attempt to restart vdr after a crash has occured (set to 0 for no limit)
MAXTRIES=10
# Minimum runtime required (in seconds) for vdr to continue restart attempts
MINRUN=20

## End Configuration Section ##

if [ ! -e "/lib/modules/`uname -r`/kernel/drivers/media/video/videodev.ko" ]; then
   echo -e "ERROR: No DVB kernel modules detected. VDR will not attempt to start. \n"
   exit 0
fi

if [ ! -e "${INSDVB}" ]; then
   echo -e "ERROR: ${INSDVB} was not detected.  Exiting. \n"
   exit 0
fi

if [ ! -e "${SVDRP}" ]; then
   echo -e "ERROR: ${SVDRP} was not detected.  Exiting. \n"
   exit 0
fi

VDRCMD="$VDRPRG -v $VIDEO_DIR -E $EPG_DIR -c $CFG_DIR -L $PLUG_DIR $OPTIONS $PLUGINS"
KILL="/usr/bin/killall -q -TERM"

# Detect whether the DVB driver is already loaded
# and return 0 if it *is* loaded, 1 if not:
function DriverLoaded()
{
  grep -qse dvb[-_]core /proc/modules
}

# Load all DVB driver modules needed for your hardware:
function LoadDriver()
{
  ${INSDVB} load
  if [ -e "${MPLAY}" ] && [ -e "${VIDEO}" ] ; then
    ${MPLAY} -frames 145 -vo mpegpes -ao mpegpes ${VIDEO} 2>/dev/null 1>/dev/null
  fi
}

# Unload all DVB driver modules loaded in LoadDriver():
function UnloadDriver()
{
  ${INSDVB} unload
}

# Load driver if it hasn't been loaded already:
if ! DriverLoaded; then
   LoadDriver
   fi

LASTRESTART=$(date +%s)
LOOPCOUNT=0
while (true) do
      if [ $LOOPCOUNT -le $MAXTRIES ] || [ $MAXTRIES -eq 0 ] ; then
        eval "$VDRCMD &"
	# Wait for VDR to initialize then do rest
        sleep 10
	${SVDRP} -d localhost "MESG VDR Startup Sequence Completed" 2>/dev/null 1>/dev/null
	touch /tmp/VDRBOOT_COMPLETE
      else
        $KILL runvdr
      fi
      # Remember PID of VDR process
      PID=$!
      # Wait for VDR to end or signal to arrive
      wait $PID
      # Remember return value of VDR
      RET=$?
      if test $RET -eq 0 -o $RET -eq 2; then exit; fi
      TIMEOFDEATH=$(date +%s)
      RUNTIME=$((TIMEOFDEATH - LASTRESTART))
      if [ $TIMEOFDEATH -le $(($LASTRESTART + $MINRUN)) ] ; then
        echo "`date` VDR crashed in $RUNTIME seconds. Minimum required runtime for VDR is $MINRUN seconds. Killing runvdr process..."
        $KILL runvdr
      fi
      echo "`date` Reloading DVB drivers"
      $KILL vdr
      sleep 10
      UnloadDriver
      LoadDriver
      LASTRESTART=$(date +%s)
      LOOPCOUNT=$((LOOPCOUNT+1))
      echo "`date` Restarting VDR $LOOPCOUNT time(s). Maximum retries set to $MAXTRIES"
      done
-------------- next part --------------
# /etc/default/vdrc
# Default VDR startup config 

# Change to 1 to enable vdr's init-script
ENABLED=1

# Location of svdrpsend.pl
SVDRP="/usr/local/bin/svdrpsend.pl"

# Location of module loading script
INSDVB="/usr/local/bin/insdvb.sh"

# DVB Device creation timeout (in seconds)
TIMEOUT=45

-------------- next part --------------
#! /bin/sh
#
# vdr start-stop script
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME="runvdr"
DESC="VDR - Linux Video Disk Recorder"
DAEMON="vdr"

ENABLED=0
test -f /etc/default/vdrc && . /etc/default/vdrc
test "$ENABLED" != "0" || exit 0

rm -f /tmp/VDRBOOT_COMPLETE

if [ ! -e "/lib/modules/`uname -r`/kernel/drivers/media/video/videodev.ko" ]; then
   echo -e "ERROR: No DVB kernel modules detected. VDR will not attempt to start. \n"
   exit 0
fi

LOOP=0
case "$1" in
  start)
         if ! ps -C vdr > /dev/null 2>&1; then
	 echo -e "Starting $DESC: $NAME. \n"
	 runvdr &
	 until [ -e /tmp/VDRBOOT_COMPLETE ] || [ $LOOP -eq $TIMEOUT ] ; do
           sleep 1
	   LOOP=$((LOOP+1))
	 done
	 if [ $LOOP -eq $TIMEOUT ]; then
	   echo -e "VDR startup sequence has timed out in $TIMEOUT seconds. VDR will not start. \n"
	   exit 1
	 fi
	 echo -e "VDR startup time was $LOOP second(s). \n"
	 echo -e "VDR startup sequence completed. \n"
	 else
	 echo -e "VDR is already running..\n"
	 fi
	 ;;
  stop)
	 if ps -C vdr > /dev/null 2>&1; then
	 echo -e "Stopping $DESC: $NAME. \n"
	 ${SVDRP} -d localhost "MESG VDR Shutdown Sequence Initialized" 2>/dev/null 1>/dev/null
	 sleep 3
	 killall -q -TERM $NAME
	 killall -q -TERM $DAEMON
	 sleep 5 
	 ${INSDVB} unload
	 else
	 echo -e "VDR is not running. \n"
	 fi
	 ;;
  restart|force-reload)
         if ps -C vdr > /dev/null 2>&1; then
	 echo -e "Restarting $DESC: $NAME. \n"
	 ${SVDRP} -d localhost "MESG VDR Restart Sequence Initialized" 2>/dev/null 1>/dev/null
	 sleep 3
	 killall -q -TERM $NAME
	 killall -q -TERM $DAEMON
	 sleep 5 
	 ${INSDVB} unload
	 sleep 2 
	 runvdr &
         until [ -e /tmp/VDRBOOT_COMPLETE ] || [ $LOOP -eq $TIMEOUT ] ; do
           sleep 1
           LOOP=$((LOOP+1))
         done
         if [ $LOOP -eq $TIMEOUT ]; then
           echo -e "VDR startup sequence has timed out in $TIMEOUT seconds. VDR will not start. \n"
           exit 1
         fi
         echo -e "VDR startup time was $LOOP second(s). \n"
	 echo -e "VDR startup sequence completed. \n"
	 else
	 echo -e "VDR is not running. \n"
	 fi
	 ;;
  *)
	 N=/etc/init.d/$NAME
	 echo "Use: $N {start|stop|restart|force-reload}" >&2
	 exit 1
	;;
esac

rm -f /tmp/VDRBOOT_COMPLETE

exit 0


More information about the vdr mailing list