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.
This commit is contained in:
Matthias P. Walther 2019-06-02 03:00:36 +02:00
parent 08a8815815
commit d40fd3e535
No known key found for this signature in database
GPG Key ID: 16BA5AB30324A4AE
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,43 @@
#!/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

View File

@ -0,0 +1 @@
*/5 * * * * /usr/bin/tunneldigger-watchdog