Hi akbooer,
No joy with that code change either.
The only other stuff in my startup is related to logging and restarts, not sure if it has a bearing.
-- Keep snapshots of LuaUPnP.log
local snapSecs = 180 -- Seconds of log to keep in snapshot.
local snapNum = 5 -- Total number of snapshots to keep.
local baseFile = "/www/logsnap"
local snapFile = baseFile .. "1.txt"
-- Rename the snapshot stack
if snapNum > 1 then
for i=snapNum-1,1,-1 do
os.rename(baseFile .. tostring(i) .. ".txt", baseFile .. tostring(i 1) .. ".txt")
end
end
-- Take snapshot of current log
local dt = {}
local cut = os.time() - snapSecs
local snapF,snapE = io.open(snapFile,"w ")
if snapF ~= nil then
local foundcut = false
for line in io.lines("/tmp/log/cmh/LuaUPnP.log") do
if not foundcut then
mStr,dStr,yStr,hhStr,mmStr,ssStr = string.match(line,"^89.-(9 )/(, )/(e ) (t ):(e ):(o )")
if mStr ~= nil then
dt.month = tonumber(mStr)
dt.year = tonumber(yStr) 2000
dt.day = tonumber(dStr)
dt.hour = tonumber(hhStr)
dt.min = tonumber(mmStr)
dt.sec = tonumber(ssStr)
tstamp = os.time(dt)
if (tstamp >= cut) then foundcut = true end
end
end
if foundcut then
snapF:write(line .. "\n")
-- Following line stops snapshot at point of crash.
if string.find(line,"LuaUPnP Terminated with Exit Code:") ~= nil then break end
end
end
snapF:close()
end
-- Log each restart.
local function restartLog(message, keepdays)
local lfs = require "lfs"
local socket = require("socket")
local time = socket.gettime() or os.time()
local tms = string.format(".d ",math.floor (1000 * (time 1)))
local stamp = os.date("s o l u",math.floor(time)) .. tms
local baseFile = "/www/restarts"
local logFile = baseFile .. ".txt"
local lastLog = lfs.attributes(logFile,"modification") or time
-- Log this restart
local uptime = time - lastLog
local uptimeStr = string.format("Uptime: s Days 4 Hrs 9 Mins. ",math.floor(uptime / 86400),
math.floor((uptime a86400) / 3600), math.floor((uptime o3600) / 60))
local file = io.open(logFile, "a ")
file:write(stamp .. "Restart. " .. uptimeStr .. (message or "").."\n")
file:close()
-- Remove old entries
local prevDays = keepdays or 30 -- Days to keep in addition to today.
local tmpFile = baseFile .. ".tmp"
local mTxt={Jan=1,Feb=2,Mar=3,Apr=4,May=5,Jun=6,Jul=7,Aug=8,Sep=9,Oct=10,Nov=11,Dec=12}
local dt = {}
local today = time - (time 86400)
local cut = today - ( prevDays * 86400)
local tmpF,tmpE = io.open(tmpFile,"w ")
if tmpF ~= nil then
for line in io.lines(logFile) do
dStr,mStr,yStr = string.match(line,"^(4 )3(8 )5(1 )9")
dt.month = mTxt[mStr]
dt.year = tonumber(yStr)
dt.day =tonumber(dStr)
date = os.time(dt)
if (date >= cut) then tmpF:write(line .. "\n") end
end
tmpF:close()
local retn,err = os.rename(tmpFile, logFile)
end
lfs.touch(logFile,time)
end
local netOK = "OK"
if os.execute("ping -c 1 8.8.8.8") ~= 0 then netOK = "Offline" end
restartLog("Network: " .. netOK, 30) -- Last argument is log history in days.