mirror of https://github.com/aredn/aredn.git
bugfix: olsrd-watchdog false triggers a reboot.
Using the method suggested by Henning Rogge in 2014 {{{ 1) remove file 2) wait 2 intervals 3) if file exists, go to 1) 4) restart olsr, then go to 1) }}} With the exception that we currently wait more than 2 intervals. Even if the script hits a collision at the same time the file is being written the file will already exist from one of the previous writes or the current write. Removing a file in use is safe as once the FD closes the file contents are fully released. Additional Advantages: * Should be more efficient to check if file exists instead of reading the file and comparing date stamps. * Removing the Perl code moves us one step closer to retiring Perl in the future.
This commit is contained in:
parent
f52513aa15
commit
fde5c1367e
|
@ -1,31 +1,28 @@
|
|||
#!/usr/bin/perl
|
||||
#!/bin/sh
|
||||
|
||||
# wait for the watchdog file to appear
|
||||
while(not -e "/tmp/olsrd.watchdog") { sleep 15 }
|
||||
|
||||
$failcount = 0;
|
||||
$last_olsrstamp = 0;
|
||||
# wait for the watchdog file to appear before starting
|
||||
while [ ! -f "/tmp/olsrd.watchdog" ]
|
||||
do
|
||||
sleep 15
|
||||
done
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
chomp ($olsr = `cat /tmp/olsrd.watchdog`);
|
||||
while true
|
||||
do
|
||||
|
||||
if ( $olsr && $olsr ne $last_olsrstamp ){
|
||||
$failcount = 0;
|
||||
} else {
|
||||
$failcount += 1;
|
||||
}
|
||||
|
||||
if( $failcount >= 3 )
|
||||
{
|
||||
($uptime) = `cat /proc/uptime` =~ /^(\d+)/;
|
||||
$date = `date`;
|
||||
system qq(echo -n "$uptime $date" >> /tmp/olsrd.log);
|
||||
system "/etc/init.d/olsrd restart";
|
||||
}
|
||||
if [ -f "/tmp/olsrd.watchdog" ]
|
||||
then
|
||||
rm -f "/tmp/olsrd.watchdog"
|
||||
else
|
||||
uptime=`cat /proc/uptime | cut -d' ' -f1`
|
||||
date=`date`
|
||||
echo "$uptime $date" >> /tmp/olsrd.log
|
||||
/etc/init.d/olsrd restart
|
||||
fi
|
||||
|
||||
$last_olsrstamp = $olsr;
|
||||
# With interval of 5 seconds this gives ~3 chances
|
||||
# for a file write before next loop.
|
||||
sleep 15
|
||||
|
||||
done
|
||||
|
||||
sleep 10;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue