get rid of library version numbers in luci olsrd code
[project/luci.git] / contrib / package / freifunk-common / files / 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") or fs.access("/var/run/olsrd4.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" 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 local tnls = io.popen("ip tunnel show | cut -d : -f 1")
27 while true do
28 tnl = tnls:read("*line")
29 if tnl == nil then break end
30 if string.find(tnl, "tnl_") == 1 then
31 os.execute(string.format("logger -t 'OLSR watchdog' 'Deleting stale tunnel %s'", tnl))
32 os.execute(string.format("ip link del %s", tnl))
33 end
34 end
35 os.execute("/etc/init.d/olsrd restart")
36 end
37 end
38 end