From 835a76e28195351d35a44c4bbde900a5739e1e57 Mon Sep 17 00:00:00 2001 From: "Matthias P. Walther" Date: Sun, 2 Jun 2019 15:59:50 +0200 Subject: [PATCH] Tunneldigger Watchdoch: refractoring and renaming of functions with respect of coding convetions. Changed logic in read_pid_file for readability. --- .../files/usr/bin/tunneldigger-watchdog | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/package/gluon-mesh-vpn-tunneldigger/files/usr/bin/tunneldigger-watchdog b/package/gluon-mesh-vpn-tunneldigger/files/usr/bin/tunneldigger-watchdog index 97596fe8..a861dafe 100755 --- a/package/gluon-mesh-vpn-tunneldigger/files/usr/bin/tunneldigger-watchdog +++ b/package/gluon-mesh-vpn-tunneldigger/files/usr/bin/tunneldigger-watchdog @@ -1,21 +1,21 @@ #!/usr/bin/lua -function restartTunneldigger() +function restart_tunneldigger() io.popen('logger -t tunneldigger-watchdog "Restarting Tunneldigger."') os.execute("/etc/init.d/tunneldigger restart") end -function readPidFile() +function read_pid_file() local pidFile = io.open("/var/run/tunneldigger.mesh-vpn.pid", "r") - local returnPid = "0" - if pidFile~=nil then - returnPid = pidFile:read("*l") - io.close(pidFile) + if not pidFile then + return nil end + returnPid = pidFile:read("*l") + io.close(pidFile) return returnPid end -function checkForMeshVpnNeighbours() +function check_for_mesh_vpn_neighbours() local handleBatctl = io.popen("batctl o", 'r') if handleBatctl~=nil then 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 io.popen("pgrep tunneldigger"):read("*l") ~= readPidFile() then io.popen('logger -t tunneldigger-watchdog "Process-Pid does not match with pid-File."') - restartTunneldigger() + restart_tunneldigger() return end - if checkForMeshVpnNeighbours() ~= true then + if check_for_mesh_vpn_neighbours() ~= true then io.popen('logger -t tunneldigger-watchdog "No vpn-mesh neighbours found."') - restartTunneldigger() + restart_tunneldigger() return end end