45 lines
1.1 KiB
Lua
Executable File
45 lines
1.1 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 checkForMeshVpnNeighbours()
|
|
local handleBatctl = io.popen("batctl o", 'r')
|
|
if handleBatctl~=nil then
|
|
for line in handleBatctl:lines() do
|
|
if line:find('mesh%-vpn') then
|
|
handleBatctl.close()
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
handleBatctl.close()
|
|
return false
|
|
end
|
|
|
|
local uci = require('simple-uci').cursor()
|
|
if uci:get_bool('tunneldigger', 'mesh_vpn', 'enabled') 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 checkForMeshVpnNeighbours() ~= true then
|
|
io.popen('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."')
|
|
restartTunneldigger()
|
|
return
|
|
end
|
|
end
|