I have a Unifi controller running on a pi. The unifi controller has a memory leak, which is not expected to be fixed soon.
So I installed domoticz on the same pi to monitor the memory usage.
When the memory usage gets very high, I would like to trigger a script, to restart the unifi service.
But it is not working. When I execute "sudo service unifi restart" using SSH the restart works.
Who can help me out?
Lua code, time based
Code: Select all
local tNow = os.date("*t");
local dayofyear = tNow.yday;
local TimeInMinutes = tNow.min + tNow.hour * 60;
commandArray = {}
mem = tonumber(otherdevices_svalues['Memory Usage'])
if mem > 85 and TimeInMinutes == 1020 then --restart at 1700 hrs
commandArray[#commandArray + 1] = {['SendNotification']='Restarting Unifi Controller, memory: '..tostring(mem).."%"}
os.execute ('(curl /bin/sleep 1 && //home/pi/domoticz/scripts/restart_unifi.sh > /dev/null)&')
end
return commandArray
Code: Select all
#!/bin/sh
sudo service unifi restart
exit 0