3e5258d9bea3c00d749e9599a822091765f5f801
[project/luci.git] / modules / freifunk / root / usr / sbin / ff_olsr_watchdog
1 #!/usr/bin/lua
2
3 require "os"
4 require "io"
5 require "uci"
6 require "posix"
7
8 if posix.access("/var/run/olsrd.pid") then
9 local stamp, intv
10 local x = uci.cursor()
11
12 x:foreach("olsrd", "LoadPlugin",
13 function(s)
14 if s.library == "olsrd_watchdog.so.0.1" then
15 intv = tonumber(s.interval)
16 stamp = s.file
17 end
18 end)
19
20 if intv and posix.access(stamp) then
21 local systime = os.time()
22 local wdgtime = tonumber(io.lines(stamp)())
23
24 if not wdgtime or ( systime - wdgtime ) > ( intv * 2 ) then
25 os.execute("logger -t 'OLSR watchdog' 'Process died - restarting!'")
26 os.execute("/etc/init.d/olsrd restart")
27 end
28 end
29 end