2019-06-02 01:00:36 +00:00
|
|
|
#!/usr/bin/lua
|
|
|
|
|
|
|
|
local uci = require('simple-uci').cursor()
|
|
|
|
|
2019-06-16 22:26:30 +00:00
|
|
|
local function restart_tunneldigger()
|
2019-06-02 01:00:36 +00:00
|
|
|
os.execute('logger -t tunneldigger-watchdog "Restarting Tunneldigger."')
|
|
|
|
os.execute('/etc/init.d/tunneldigger restart')
|
|
|
|
end
|
|
|
|
|
2019-06-16 22:26:30 +00:00
|
|
|
local function read_pid_file()
|
2019-06-02 01:00:36 +00:00
|
|
|
local pid_file = io.open('/var/run/tunneldigger.mesh-vpn.pid', 'r')
|
|
|
|
if not pid_file then
|
|
|
|
return nil
|
|
|
|
end
|
2019-06-16 22:26:30 +00:00
|
|
|
local pid = pid_file:read('*l')
|
2019-06-02 01:00:36 +00:00
|
|
|
pid_file:close()
|
|
|
|
return pid
|
|
|
|
end
|
|
|
|
|
2019-06-16 22:26:30 +00:00
|
|
|
local function has_mesh_vpn_neighbours()
|
2019-06-02 01:00:36 +00:00
|
|
|
local handle = io.popen('batctl o', 'r')
|
|
|
|
if not handle then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
for line in handle:lines() do
|
|
|
|
if line:find('mesh%-vpn') then
|
|
|
|
handle:close()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
handle:close()
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if uci:get_bool('tunneldigger', 'mesh_vpn', 'enabled') then
|
|
|
|
if io.popen('pgrep tunneldigger'):read('*l') ~= read_pid_file() then
|
|
|
|
os.execute('logger -t tunneldigger-watchdog "Process-Pid does not match with pid-File."')
|
|
|
|
restart_tunneldigger()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not has_mesh_vpn_neighbours() then
|
|
|
|
os.execute('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."')
|
|
|
|
restart_tunneldigger()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|