Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add watchdog script written in Lua to the gluon-mesh-vpn-tunneldigger #1735

Closed
wants to merge 11 commits into from
Closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/lua

function restart_tunneldigger()
io.popen('logger -t tunneldigger-watchdog "Restarting Tunneldigger."')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't parse any return values we might use os.execute here as well, no?

os.execute("/etc/init.d/tunneldigger restart")
end

function read_pid_file()
local pidFile = io.open("/var/run/tunneldigger.mesh-vpn.pid", "r")
if not pidFile then
return nil
end
returnPid = pidFile:read("*l")
io.close(pidFile)
return returnPid
end

function check_for_mesh_vpn_neighbours()
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."')
restart_tunneldigger()
return
end
if check_for_mesh_vpn_neighbours() ~= true then
io.popen('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."')
restart_tunneldigger()
return
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/5 * * * * /usr/bin/tunneldigger-watchdog