summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2011-11-08 15:49:20 (GMT)
committer Jaromil <jaromil@dyne.org>2011-12-13 16:38:10 (GMT)
commitcc4571fcab7b11dd36dc2170f360bfe1fe9056eb (patch)
tree8ef4b550895a8522970473f6d580654d474130c0
parent65c2b66f6065e225f3dbcb16fd5b294e7ed4dffd (diff)
Watchdog script and fixes
contributed by Michael van Rosmalen - WATCHDOGTIMER can be set in the hdsync.conf file - HDSYNC_SLEEP is now in micro seconds instead of seconds to compensate for hardware differences - HDSYNC_NETWORK can be set to MANUAL in the hdsync.conf file more redundant network synchronization
-rw-r--r--scripts/S88hdsync14
-rw-r--r--scripts/hdsync.conf8
-rwxr-xr-xscripts/listen-sync.sh72
-rwxr-xr-xscripts/offer-sync.sh94
-rw-r--r--scripts/utils-sync.sh36
-rwxr-xr-xscripts/watchdog.sh51
6 files changed, 160 insertions, 115 deletions
diff --git a/scripts/S88hdsync b/scripts/S88hdsync
index 9cec935..8e4b792 100644
--- a/scripts/S88hdsync
+++ b/scripts/S88hdsync
@@ -70,7 +70,7 @@ get_ip
get_bins $APPROOT
if [ $HDSYNC_SLEEP ]; then
- echo "SLEEP adjust set to $HDSYNC_SLEEP seconds" >> /tmp/hdsync.log
+ echo "SLEEP adjust set to $HDSYNC_SLEEP useconds" >> /tmp/hdsync.log
fi
UPNPPORT="`lsof -a -i4 -sTCP:LISTEN -c DMARender -F n | awk -v FS=':' '/^n/ {print $2}'`"
@@ -91,7 +91,16 @@ killall pandora_ep
killall apache2
killall smbtree
-
+if test $WATCHDOGTIMER -gt 0; then
+ #start watchdog timer
+ echo "starting watchdog, movielenght is $WATCHDOGTIMER"
+ ps | grep watchdog | grep -v grep
+ if [ $? -ne 0 ]; then
+ rm -f /tmp/hdsync.error
+ touch /tmp/hdsync.error
+ $APPROOT/bin/watchdog.sh >> /tmp/hdsync.error &
+ fi
+fi
if [ "$HDSYNC_CHANNEL" = "1" ]; then
echo "Offering sync" >> /tmp/hdsync.log
@@ -100,3 +109,4 @@ else
echo "Listening for sync offers" >> /tmp/hdsync.log
$APPROOT/bin/listen-sync.sh >> /tmp/hdsync.log
fi
+
diff --git a/scripts/hdsync.conf b/scripts/hdsync.conf
index bbe40e6..abbf40f 100644
--- a/scripts/hdsync.conf
+++ b/scripts/hdsync.conf
@@ -3,7 +3,8 @@
# Network configuration to use: DYNAMIC or STATIC
# DYNAMIC = use the DHCP daemon on LAN to assign IPs
-# STATIC = most of the time you'll need this
+# STATIC = auto-configure IPs for LAN (use this if you don't know)
+# MANUAL = don't change the current configuration
HDSYNC_NETWORK=DYNAMIC
# number of this video channel
@@ -16,3 +17,8 @@ HDSYNC_SLEEP=0
# total video channels expected
TOTAL_CHANNELS=2
+# watchdog activation
+# if you like to run an additional watchdog process to look over
+# the playback and avoid long-term freezes, fill in here the duration
+# of the video in seconds, approximated to the minimum (experimental feature)
+# WATCHDOGTIMER=360
diff --git a/scripts/listen-sync.sh b/scripts/listen-sync.sh
index fbe5aba..046d370 100755
--- a/scripts/listen-sync.sh
+++ b/scripts/listen-sync.sh
@@ -4,7 +4,7 @@
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
+# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@@ -28,78 +28,62 @@ touch /tmp/hdsync.reply
echo $answer >> /tmp/hdsync.reply
done) &
-# # check that the video is prepared
-# while [ true ]; do
-# sleep 3
-# lsof | grep 'mnt.*video' > /dev/null
-# if [ $? == 0 ]; then # a video is loaded
-# break
-# fi
-# done
-
# loop continuously
while [ true ]; do
- sync
-
sleep 10
# check the state of the video
state=`$AV -s localhost -p $UPNPPORT get 2>&1| awk '/^TInfo:/ {print $2}'`
+ echo "`date +%T` state (avremote) is $state"
if [ "$state" == "NO_MEDIA_PRESENT" ]; then
- # will get ready for sync
+ # will get ready for sync
prepare_play >> /tmp/hdsync.log
elif [ "$state" == "STOPPED" ]; then
- # will get ready for sync again
+ # will get ready for sync again
prepare_play >> /tmp/hdsync.log
elif [ "$state" == "PAUSED_PLAYBACK" ]; then
- # will sync start
-
+ # will sync start
+
rm -f /tmp/hdsync.reply
touch /tmp/hdsync.reply
-
- echo "listening for offers on $IP"
-
+
+ echo "`date +%T` listening for offers on $IP"
+
offer="`echo | $NC -c -u -l -p 3332`"
-
- echo "offered sync by $offer"
-
-
- # repeat udp replies to offer until ack
- echo "replying with our ip until ack"
+
+ echo "`date +%T` offered sync by $offer"
+
+ # repeat udp replies to offer until ack
+ echo "`date +%T` replying with our ip until ack"
ack=""
while [ "$ack" = "" ]; do
sleep 1
echo "$IP" | $NC -c -u $offer 3331
echo -n "."
ack=`cat /tmp/hdsync.reply`
- done
-
- echo "ack received, we are channel $ack"
-
- sync
-
- echo "ready: awaiting syncstarter signal"
-
-
- # exit after connection (-e true)
+ done
+
+ echo "`date +%T` ack received, we are channel $ack"
+
+
+ echo "`date +%T` ready: awaiting syncstarter signal"
+
+
+ # exit after connection (-e true)
$NC -c -u -l -p 3336 -e true
-
+
if [ $HDSYNC_SLEEP ]; then
- sleep $HDSYNC_SLEEP
+ usleep $HDSYNC_SLEEP
fi
-
- # "press play on tape"
- $SYNC -s localhost -p $UPNPPORT start
-
- echo "sync playback started on `date +%T`"
+ # "press play on tape"
+ $SYNC -s localhost -p $UPNPPORT start
+ echo "`date +%T` sync playback started"
fi
done
-
-
diff --git a/scripts/offer-sync.sh b/scripts/offer-sync.sh
index e3a06a8..dfc23b4 100755
--- a/scripts/offer-sync.sh
+++ b/scripts/offer-sync.sh
@@ -4,7 +4,7 @@
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
+# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@@ -23,87 +23,83 @@ PATH=/usr/bin:/bin:/usr/sbin:/sbin
rm -f /tmp/hdsync.reply
touch /tmp/hdsync.reply
(while [ true ]; do
- answer=`echo | $NC -c -u -l -p 3331`;
+ answer=`echo | $NC -c -u -l -p 3331 | awk '{print $1}'`;
echo $answer >> /tmp/hdsync.reply
+ echo $answer | $NC -c -u $answer 3333
+ echo "`date +%T` ack sent to $answer"
done) &
-# # check that the video is prepared
-# while [ true ]; do
-# sleep 3
-# lsof | grep 'mnt.*video' > /dev/null
-# if [ $? == 0 ]; then # a video is loaded
-# break
-# fi
-# done
-
# loop continuously
while [ true ]; do
- sync
-
sleep 10
# check the state of the video
state=`$AV -s localhost -p $UPNPPORT get 2>&1| awk '/^TInfo:/ {print $2}'`
+ echo "`date +%T` state (avremote) is $state"
if [ "$state" == "NO_MEDIA_PRESENT" ]; then
- # will get ready for sync
+ # will get ready for sync
prepare_play >> /tmp/hdsync.log
elif [ "$state" == "STOPPED" ]; then
- # will get ready for sync again
+ # will get ready for sync again
prepare_play >> /tmp/hdsync.log
elif [ "$state" == "PAUSED_PLAYBACK" ]; then
- # will sync start
+ # will sync start
rm -f /tmp/hdsync.reply
touch /tmp/hdsync.reply
- echo "broadcasting offer signals from $IP"
+ echo "`date +%T` broadcasting offer signals from $IP"
# we do broadcast only on class C
# must always make sure also listener expects on class C
bcast=`echo $IP | awk 'BEGIN { FS="." } {print $1 "." $2 "." $3 }'`.255
echo "to netmask $bcast"
-
- # send broadcast signals until somebody listens
+
+ # send broadcast signals until somebody listens
listeners=0
expected=`expr $TOTAL_CHANNELS - 1`
- while [ "$listeners" != "$expected" ]; do
- echo -n "$b: `date +%X` "
+ while [ $listeners -lt $expected ]; do
+ echo -n "`date +%X` "
$BC $bcast 3332 $IP
- sleep 2
listeners=`cat /tmp/hdsync.reply | sort | uniq | wc -w`
+ sleep 1
done
- echo "harvesting replies"
- cat /tmp/hdsync.reply | sort | uniq > /tmp/hdsync.listeners
-
- echo "sending acks"
- c=1
- for l in `cat /tmp/hdsync.listeners`; do
- echo "$c: $l"
- echo "$c" | $NC -c -u $l 3333
- done
-
-
- echo "waiting for other players to get ready..."
- sync
- sleep 10
-
- # sync start!
- $BC $bcast 3336 s
-
- if [ $HDSYNC_SLEEP ]; then
- sleep $HDSYNC_SLEEP
- fi
-
- # "press play on tape"
- $SYNC -s localhost -p $UPNPPORT start
-
- echo "sync playback started on `date +%T`"
+# echo "harvesting replies"
+# cat /tmp/hdsync.reply | sort | uniq > /tmp/hdsync.listeners
+#
+# echo "sending acks"
+# c=1
+# for l in `cat /tmp/hdsync.listeners`; do
+# echo "$c: $l"
+# echo "$c" | $NC -c -u $l 3333
+# done
+
+ echo "`date +%T` waiting for other players to get ready..."
+ sync
+
+ # sync start in 2 seconds!
+ (sleep 2
+ $BC $bcast 3336 s >> /dev/null) &
+
+ # exit after connection (-e true)
+ $NC -c -u -l -p 3336 -e true
+
+ if [ $HDSYNC_SLEEP ]; then
+ usleep $HDSYNC_SLEEP
+ fi
+
+ # "press play on tape"
+ $SYNC -s localhost -p $UPNPPORT start
+ echo "`date +%T` sync playback started"
fi
-done \ No newline at end of file
+
+# $BC $bcast 3336 s >> /dev/null # keep broadcasting in case someone didnt get the message
+
+done
diff --git a/scripts/utils-sync.sh b/scripts/utils-sync.sh
index 9d6dc4f..9b731a2 100644
--- a/scripts/utils-sync.sh
+++ b/scripts/utils-sync.sh
@@ -4,7 +4,7 @@
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
+# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@@ -23,17 +23,20 @@ get_conf() {
get_ip() {
if [ "$HDSYNC_NETWORK" = "DYNAMIC" ]; then
- echo "listening for DHCP assigned IP on the network"
+ echo "`date +%T` listening for DHCP assigned IP on the network"
config_tool -c LAN_TYPE='d'
IP=`get_conf IP2`
- else
- echo "setting a static network address"
+ elif [ "$HDSYNC_NETWORK" = "STATIC" ]; then
+ echo "`date +%T` setting a static network address"
IP="192.168.0.$HDSYNC_CHANNEL"
config_tool -c LAN_TYPE='s'
config_tool -c IP2=$IP
config_tool -c NETMASK2=255.255.255.0
ifconfig eth0 $IP netmask 255.255.255.0
- echo "network interface configured with address $IP ..."
+ echo "`date +%T` network interface configured with address $IP ..."
+ else
+ IP=`get_conf IP2`
+ echo "`date +%T` network interface manualy configured with address $IP ..."
fi
export IP
}
@@ -42,19 +45,19 @@ get_ip() {
get_bins() {
# wrapper to test in development on local paths
if [ -z $1 ]; then
- NC="../src/netcat"
- BC="../src/broadcaster"
- AV="../src/avremote"
- SYNC="../src/hdsync"
+ NC="../src/netcat"
+ BC="../src/broadcaster"
+ AV="../src/avremote"
+ SYNC="../src/hdsync"
else
- NC="$APPROOT/bin/netcat"
- BC="$APPROOT/bin/broadcaster"
- AV="$APPROOT/bin/avremote"
- SYNC="$APPROOT/bin/hdsync"
+ NC="$APPROOT/bin/netcat"
+ BC="$APPROOT/bin/broadcaster"
+ AV="$APPROOT/bin/avremote"
+ SYNC="$APPROOT/bin/hdsync"
fi
- echo "hdsync binaries found:"
+ echo "`date +%T` hdsync binaries found:"
echo "$BC"
echo "$NC"
echo "$AV"
@@ -65,9 +68,4 @@ get_bins() {
prepare_play() {
file=`ls $USBROOT/video`
$SYNC -s localhost -p $UPNPPORT prepare "$USBROOT/video/$file"
-
- # hdsync prepare makes: load, play and pause
- sync
-
- echo "ready to play on `date +%T`"
}
diff --git a/scripts/watchdog.sh b/scripts/watchdog.sh
new file mode 100755
index 0000000..df8a07b
--- /dev/null
+++ b/scripts/watchdog.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# Copyright (C) 2011 Michael van Rosmalen <mvanrosmalen@zya.nl>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+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=`$AV -s localhost -p $UPNPPORT get 2>&1| awk '/^TInfo:/ {print $2}'`
+
+ 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"
+ $AV -s localhost -p $UPNPPORT stop
+ sleep 5
+ $AV -s localhost -p $UPNPPORT stop
+ timer=`expr $watchdogtimer - 60`
+ fi
+laststate="$state"
+
+done