modules/freifunk: add olsrd watchdog script, remove olsrd interface defaults
[project/luci.git] / modules / freifunk / root / usr / sbin / ff_olsr_watchdog
diff --git a/modules/freifunk/root/usr/sbin/ff_olsr_watchdog b/modules/freifunk/root/usr/sbin/ff_olsr_watchdog
new file mode 100755 (executable)
index 0000000..2b4fabe
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/lua
+
+require "os"
+require "io"
+require "uci"
+require "posix"
+
+if posix.access("/var/run/olsrd.pid") then
+       local stamp, intv
+       local x = uci.cursor()
+
+       x:foreach("olsrd", "LoadPlugin",
+               function(s)
+                       if s.library == "olsrd_watchdog.so.0.1" then
+                               intv  = tonumber(s.interval)
+                               stamp = s.file
+                       end
+               end)
+
+       if intv and posix.access(stamp) then
+               local systime = os.time()
+               local wdgtime = tonumber(io.lines(stamp)())
+
+               if not wdgtime or ( systime - wdgtime ) > intv then
+                       os.execute("logger -t 'OLSR watchdog' 'Process died - restarting!'")
+                       os.execute("/etc/init.d/olsrd restart")
+               end
+       end
+end