Tunneldigger Watchdoch: refractoring and renaming of variable names with respect to coding convetions.

This commit is contained in:
Matthias P. Walther 2019-06-02 16:55:49 +02:00
parent 835a76e281
commit 3258c36f1c
No known key found for this signature in database
GPG Key ID: 16BA5AB30324A4AE

View File

@ -6,37 +6,37 @@ function restart_tunneldigger()
end end
function read_pid_file() function read_pid_file()
local pidFile = io.open("/var/run/tunneldigger.mesh-vpn.pid", "r") local pid_file = io.open("/var/run/tunneldigger.mesh-vpn.pid", "r")
if not pidFile then if not pid_file then
return nil return nil
end end
returnPid = pidFile:read("*l") pid = pid_file:read("*l")
io.close(pidFile) pid_file:close()
return returnPid return pid
end end
function check_for_mesh_vpn_neighbours() function check_for_mesh_vpn_neighbours()
local handleBatctl = io.popen("batctl o", 'r') local handle_batctl = io.popen("batctl o", 'r')
if handleBatctl~=nil then if handle_batctl~=nil then
for line in handleBatctl:lines() do for line in handle_batctl:lines() do
if line:find('mesh%-vpn') then if line:find('mesh%-vpn') then
handleBatctl.close() handle_batctl:close()
return true return true
end end
end end
end end
handleBatctl.close() handle_batctl:close()
return false return false
end end
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
if uci:get_bool('tunneldigger', 'mesh_vpn', 'enabled') then 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."') io.popen('logger -t tunneldigger-watchdog "Process-Pid does not match with pid-File."')
restart_tunneldigger() restart_tunneldigger()
return return
end 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."') io.popen('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."')
restart_tunneldigger() restart_tunneldigger()
return return