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
Expand Up @@ -6,37 +6,37 @@ function restart_tunneldigger()
end

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

function check_for_mesh_vpn_neighbours()
local handleBatctl = io.popen("batctl o", 'r')
if handleBatctl~=nil then
for line in handleBatctl:lines() do
local handle_batctl = io.popen("batctl o", 'r')
if handle_batctl~=nil then
for line in handle_batctl:lines() do
if line:find('mesh%-vpn') then
handleBatctl.close()
handle_batctl:close()
return true
end
end
end
handleBatctl.close()
handle_batctl: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
if io.popen("pgrep tunneldigger"):read("*l") ~= read_pid_file() 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
if not check_for_mesh_vpn_neighbours() then
io.popen('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."')
restart_tunneldigger()
return
Expand Down