The current program exit-codes:
0 = Help, signal (e.g. kill -HUP) 1 = Emergency exit 2 = Error during initialization (commandline, config, device...)
At the moment I have a script, which sends a kill signal to leave the endless loop = end vdr. The problem is that in runvdr I simply can't decide whether a normal shutdown through my script happened or some other signal, e.g. watchdog, kicked in, since all signals return "0".
In my eyes both cases should have different exit-codes.
Regards, Patrick
I demand that Patrick Gleichmann may or may not have written...
The current program exit-codes:
0 = Help, signal (e.g. kill -HUP) 1 = Emergency exit 2 = Error during initialization (commandline, config, device...)
At the moment I have a script, which sends a kill signal to leave the endless loop = end vdr. [...]
Make at least N attempts to start vdr and record the start time for each of the last N attempts. Once N attempts have been made, if the oldest of these is too recent, stop trying to restart it.
My runvdr does this (see .sig; you want vdr_1.3.44-2.diff.gz).
If you want to do this in shell then something like the following (untested) should be adequate:
#! /bin/ash
# ...
START_1= START_2= START_3= START_4= START_5=
while :; do START_1="$START_2" START_2="$START_3" START_3="$START_4" START_4="$START_5" START_5="`date +"%s"`"
# run vdr here
NOW="`date +"%s"`" test $(($NOW - $START_1)) -lt 60 && break done
Patrick Gleichmann wrote:
At the moment I have a script, which sends a kill signal to leave the endless loop = end vdr. The problem is that in runvdr I simply can't decide whether a normal shutdown through my script happened or some other signal, e.g. watchdog, kicked in, since all signals return "0".
I'm going a different way: I've implemented signal handling in my runvdr itself. That way I can kill runvdr, and runvdr will kill vdr, and of course knows that vdr doesn't need to be restarted.
Simplified, it works like this:
SIG= trap "SIG=TERM" SIGTERM
# run vdr eval "$VDRCMD" & VDRPID=$!
# wait for VDR terminating or signal caught wait $VDRPID VDRRETURN=$?
if [ "$SIG" = "TERM" ] ; then # runvdr was killed kill $VDRPID # dont restart else # normal termination, decide on errorlevel $VDRRETURN fi
Cheers,
Udo
Thanks alot. I will try both solutions on the upcoming weekend.
Patrick