luci/contrib/package/freifunk-common/files/usr/sbin/ff_olsr_watchdog
Philipp Borgers 5f65547dfd get rid of library version numbers in luci olsrd code
Signed-off-by: Philipp Borgers <borgers@mi.fu-berlin.de>
2018-10-25 21:56:06 +02:00

38 lines
1,006 B
Lua
Executable file

#!/usr/bin/lua
require "os"
require "io"
require "uci"
local fs = require "nixio.fs"
if fs.access("/var/run/olsrd.pid") or fs.access("/var/run/olsrd4.pid") then
local stamp, intv
local x = uci.cursor()
x:foreach("olsrd", "LoadPlugin",
function(s)
if s.library == "olsrd_watchdog" then
intv = tonumber(s.interval)
stamp = s.file
end
end)
if intv and fs.access(stamp) then
local systime = os.time()
local wdgtime = tonumber(io.lines(stamp)())
if not wdgtime or ( systime - wdgtime ) > ( intv * 2 ) then
os.execute("logger -t 'OLSR watchdog' 'Process died - restarting!'")
local tnls = io.popen("ip tunnel show | cut -d : -f 1")
while true do
tnl = tnls:read("*line")
if tnl == nil then break end
if string.find(tnl, "tnl_") == 1 then
os.execute(string.format("logger -t 'OLSR watchdog' 'Deleting stale tunnel %s'", tnl))
os.execute(string.format("ip link del %s", tnl))
end
end
os.execute("/etc/init.d/olsrd restart")
end
end
end