Commit 2ca33e1c authored by Tomas Hlavacek's avatar Tomas Hlavacek

Add logfile size control to the ulg-cron

Logfile may grow to huge sizes when ULG runs with debug on.
To avoid situation there is a check of the size and eventual removal of
the overgrown logfile.
parent b804cd90
...@@ -32,6 +32,7 @@ import ulgmodel ...@@ -32,6 +32,7 @@ import ulgmodel
### ULG cron script ### ULG cron script
SESSION_FILE_REGEX='^ulg-.*\.session$' SESSION_FILE_REGEX='^ulg-.*\.session$'
LOGFILE_LIMIT=1048576
class ULGCron: class ULGCron:
def __init__(self): def __init__(self):
...@@ -57,8 +58,17 @@ class ULGCron: ...@@ -57,8 +58,17 @@ class ULGCron:
else: else:
ulgmodel.log('Not removing file '+fp+' because it is not at least 1 hour old.') ulgmodel.log('Not removing file '+fp+' because it is not at least 1 hour old.')
def clearLog(self):
try:
if(os.stat(defaults.log_file).st_size > LOGFILE_LIMIT):
os.unlink(defaults.log_file)
except OSError as e:
ulgmodel.log('Error while checking/removing logfile '+defaults.log_file+' '+str(e))
ulgmodel.log("Logfile removed due to excessive size. Please set logrotate to keep the file size below "+str(LOGFILE_LIMIT)+" bytes.")
def run(self): def run(self):
ulgmodel.log('ULG cron run.') ulgmodel.log('ULG cron run.')
self.clearLog()
self.rescanRouters() self.rescanRouters()
self.clearSessions() self.clearSessions()
ulgmodel.log('ULG cron finished.') ulgmodel.log('ULG cron finished.')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment