Tunneldigger Watchdoch: refractoring and renaming of functions with respect of coding convetions. Changed logic in read_pid_file for readability.

This commit is contained in:
Matthias P. Walther 2019-06-02 15:59:50 +02:00
parent 82b00d8319
commit 835a76e281
No known key found for this signature in database
GPG Key ID: 16BA5AB30324A4AE

View File

@ -1,21 +1,21 @@
#!/usr/bin/lua #!/usr/bin/lua
function restartTunneldigger() function restart_tunneldigger()
io.popen('logger -t tunneldigger-watchdog "Restarting Tunneldigger."') io.popen('logger -t tunneldigger-watchdog "Restarting Tunneldigger."')
os.execute("/etc/init.d/tunneldigger restart") os.execute("/etc/init.d/tunneldigger restart")
end end
function readPidFile() function read_pid_file()
local pidFile = io.open("/var/run/tunneldigger.mesh-vpn.pid", "r") local pidFile = io.open("/var/run/tunneldigger.mesh-vpn.pid", "r")
local returnPid = "0" if not pidFile then
if pidFile~=nil then return nil
returnPid = pidFile:read("*l")
io.close(pidFile)
end end
returnPid = pidFile:read("*l")
io.close(pidFile)
return returnPid return returnPid
end end
function checkForMeshVpnNeighbours() function check_for_mesh_vpn_neighbours()
local handleBatctl = io.popen("batctl o", 'r') local handleBatctl = io.popen("batctl o", 'r')
if handleBatctl~=nil then if handleBatctl~=nil then
for line in handleBatctl:lines() do for line in handleBatctl:lines() do
@ -33,12 +33,12 @@ 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") ~= readPidFile() 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."')
restartTunneldigger() restart_tunneldigger()
return return
end end
if checkForMeshVpnNeighbours() ~= true then if check_for_mesh_vpn_neighbours() ~= true then
io.popen('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."') io.popen('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."')
restartTunneldigger() restart_tunneldigger()
return return
end end
end end