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