summaryrefslogtreecommitdiffstats
path: root/scripts/watchdog.sh
blob: e0fbc7b52ad04a7c725dfdcb4e214c19a48bb3d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
#

PATH=/usr/bin:/bin:/usr/sbin:/sbin

. $APPROOT/bin/utils-sync.sh
. $USBROOT/hdsync.conf

watchdogtimer=`expr $WATCHDOGTIMER + 30`    #timeout in seconds, movielength + some
timer=0

echo "`date +%T` watchdog started, timeout is $watchdogtimer"

# loop continuously
while [ true ]; do

    sleep 5
    timer=`expr $timer + 5`

    # check the state of the video
    state=`upnp-cmd GetTransportInfo | awk '/CurrentTransportState/ {print $3}'`

    if [ "$state" != $laststate ]; then
        echo "`date +%T` watchdog timer reset after state change to $state"
        timer=0     # reset timer
    fi

    if [ $timer -gt $watchdogtimer ]; then
        echo "`date +%T` watchdog timer exceeded, trying to resolve"
        upnp-cmd stop
        sleep 5
        upnp-cmd stop
        timer=`expr $watchdogtimer - 60`
    fi
laststate="$state"

done