gluon/package/gluon-mesh-vpn-tunneldigger/files/usr/bin/tunneldigger-watchdog
Matthias P. Walther d40fd3e535
Add watchdog script written in Lua to the gluon-mesh-vpn-tunneldigger
package.

The logic is based on the former watchdog written in (B)ash.

The code was written bei Robin Weiligmann <admin@robwei.me> and me.
2019-06-02 03:00:36 +02:00

44 lines
1.2 KiB
Lua
Executable File

#!/usr/bin/lua
function restartTunneldigger()
io.popen('logger -t tunneldigger-watchdog "Restarting Tunneldigger."')
os.execute("/etc/init.d/tunneldigger restart")
end
function readPidFile()
local pidFile = io.open("/var/run/tunneldigger.mesh-vpn.pid", "r")
local returnPid = "0"
if pidFile~=nil then
returnPid = pidFile:read("*l")
io.close(pidFile)
end
return returnPid
end
function getNeighbourCount()
local list = io.lines("/sys/kernel/debug/batman_adv/bat0/originators")
if list~=nil then
for line in list do
if line:find('mesh%-vpn') then
return 1
end
end
end
return nil
end
local uci = require('simple-uci').cursor()
local tunneldiggerEnabled = uci:get_bool('tunneldigger', 'mesh_vpn', 'enabled')
if tunneldiggerEnabled then
if io.popen("pgrep tunneldigger"):read("*l") ~= readPidFile() then
io.popen('logger -t tunneldigger-watchdog "Process-Pid does not match with pid-File."')
restartTunneldigger()
return
end
if getNeighbourCount() ~= 1 then
io.popen('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."')
restartTunneldigger()
return
end
end