From: Kristian Kræmmer Nielsen Date: Wed, 1 Mar 2017 12:10:54 +0000 (+0100) Subject: Added handling of failed stream - reset X-Git-Url: https://git.jkkn.net/?a=commitdiff_plain;h=0527cbdb66490c29a46c6ef1c5576328e2af8a4b;p=dai-monitor.git Added handling of failed stream - reset --- diff --git a/monitor-dai.sh b/monitor-dai.sh index dba88cd..553fbad 100755 --- a/monitor-dai.sh +++ b/monitor-dai.sh @@ -102,6 +102,8 @@ function monitorStream() { local expectedAdLength=-1 local mode="UNKNOWN" local curLength=0 + local failed=0 + local target_duration=$TARGET_DURATION real_time=$(date +%s) stream_time=$(($real_time - $STREAM_TIME_SCREW)) @@ -134,7 +136,7 @@ function monitorStream() { stream_time=$(echo "$stream_time + $nextSegmentLength" | bc) pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S") if [[ $curSeq -ne $nextSeq ]]; then - echo >&2 "$pretty_time: Skipped a segment by mistake ($curSeq > $nextSeq)" + echo >&2 "$pretty_time: WARN: Skipped a segment by mistake ($curSeq > $nextSeq)" fi #echo >&2 "$pretty_time: Current mode length: $curLength" nextSeq=$(($curSeq + 1)) @@ -149,9 +151,9 @@ function monitorStream() { tag="${BASH_REMATCH[1]}" value="${BASH_REMATCH[2]}" if [ "$tag" == "EXT-X-TARGETDURATION" ]; then - if [ "$value" != "$TARGET_DURATION" ]; then - echo "$pretty_time: Changing target durationt to: $value" - TARGET_DURATION="$value" + if [ "$value" != "$target_duration" ]; then + echo "$pretty_time: Changing target duration to: $value" + target_duration="$value" fi elif [ "$tag" == "EXTINF" ]; then nextSegmentLength=$value @@ -193,25 +195,37 @@ function monitorStream() { if [ $warn_not_a_playlist -eq 1 ]; then echo >&2 "$pretty_time: ERROR: Not a valid playlist ($stream)" + failed=$(($failed + 1)) + else + failed=0 fi else - echo >&2 "$pretty_time: Unable to request: $stream" + echo >&2 "$pretty_time: Unable to request: $stream" + failed=$(($failed + 1)) fi rm "$TMPFILE" endtime=$(date +%s) - waittime=$(($TARGET_DURATION - ($endtime-$starttime))) + waittime=$(($target_duration - ($endtime-$starttime))) if [ "$waittime" -gt 0 ]; then sleep $waittime fi + + if [ "$failed" -ge 2 ]; then + echo >&2 "$pretty_time: ERROR: Stream failed twice.. resetting..." + return + fi done } -streamurl=$(resolveFirstStream "$1") -if [ -e "$streamurl" ]; then - echo >&2 "Invalid HLS-stream: $1" -fi +while true; do + streamurl=$(resolveFirstStream "$1") + if [ -e "$streamurl" ]; then + echo >&2 "Invalid HLS-stream: $1" + sleep 10 + fi + monitorStream "$streamurl" +done -monitorStream "$streamurl"