Drop support for luaposix and bitlib (obsoleted by nixio)
[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 local fs = require "nixio.fs"
7
8 if fs.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 fs.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