Protect against unintended log deletions in logmgmt
The logmgmt daemon is using a "logrotate -d" query to determine the list of monitored files. If that query fails, logmgmt should not purge unmonitored files, as it may be deleting files that should be protected. Change-Id: I8a0b092fdbe8fccb8cf493dc631c22e1d7156269 Signed-off-by: Don Penney <don.penney@windriver.com> Signed-off-by: Scott Little <scott.little@windriver.com>
This commit is contained in:
parent
696e01e065
commit
636898cd68
@ -129,8 +129,11 @@ class LogMgmtDaemon():
|
|||||||
self.monitored_files.extend(glob.glob(fields[2]))
|
self.monitored_files.extend(glob.glob(fields[2]))
|
||||||
self.monitored_files.extend(glob.glob(fields[2] + '.[0-9].gz'))
|
self.monitored_files.extend(glob.glob(fields[2] + '.[0-9].gz'))
|
||||||
self.monitored_files.extend(glob.glob(fields[2] + '.[0-9][0-9].gz'))
|
self.monitored_files.extend(glob.glob(fields[2] + '.[0-9][0-9].gz'))
|
||||||
|
self.monitored_files.extend(glob.glob(fields[2] + '.[0-9]'))
|
||||||
|
self.monitored_files.extend(glob.glob(fields[2] + '.[0-9][0-9]'))
|
||||||
except:
|
except:
|
||||||
logging.error('Failed to determine monitored files')
|
logging.error('Failed to determine monitored files')
|
||||||
|
raise
|
||||||
|
|
||||||
def get_unmonitored_files(self):
|
def get_unmonitored_files(self):
|
||||||
self.unmonitored_files = []
|
self.unmonitored_files = []
|
||||||
@ -214,6 +217,7 @@ class LogMgmtDaemon():
|
|||||||
logging.warning("Reached critical disk usage for /var/log: %d%% free" % pf)
|
logging.warning("Reached critical disk usage for /var/log: %d%% free" % pf)
|
||||||
|
|
||||||
# We're running out of disk space, so we need to start deleting files
|
# We're running out of disk space, so we need to start deleting files
|
||||||
|
try:
|
||||||
for index in range(20, 11, -1):
|
for index in range(20, 11, -1):
|
||||||
logging.info("/var/log is %d%% free. Purging rotated .%d.gz files to free space" % (pf, index))
|
logging.info("/var/log is %d%% free. Purging rotated .%d.gz files to free space" % (pf, index))
|
||||||
self.get_monitored_files()
|
self.get_monitored_files()
|
||||||
@ -225,6 +229,8 @@ class LogMgmtDaemon():
|
|||||||
logging.info("/var/log is %d%% free. Running logrotate" % pf)
|
logging.info("/var/log is %d%% free. Running logrotate" % pf)
|
||||||
self.run_logrotate()
|
self.run_logrotate()
|
||||||
return
|
return
|
||||||
|
except Exception as e:
|
||||||
|
logging.exception('Failed purging rotated files', e)
|
||||||
|
|
||||||
# We still haven't freed up enough space, so try a logrotate
|
# We still haven't freed up enough space, so try a logrotate
|
||||||
logging.info("/var/log is %d%% free. Running logrotate" % pf)
|
logging.info("/var/log is %d%% free. Running logrotate" % pf)
|
||||||
@ -243,6 +249,7 @@ class LogMgmtDaemon():
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Start deleting unmonitored files
|
# Start deleting unmonitored files
|
||||||
|
try:
|
||||||
self.get_monitored_files()
|
self.get_monitored_files()
|
||||||
self.get_unmonitored_files()
|
self.get_unmonitored_files()
|
||||||
logging.info("/var/log is %d%% free. Deleting unmonitored files to free space" % pf)
|
logging.info("/var/log is %d%% free. Deleting unmonitored files to free space" % pf)
|
||||||
@ -256,6 +263,8 @@ class LogMgmtDaemon():
|
|||||||
if pf >= PERCENT_FREE_MAJOR:
|
if pf >= PERCENT_FREE_MAJOR:
|
||||||
logging.info("/var/log is %d%% free." % pf)
|
logging.info("/var/log is %d%% free." % pf)
|
||||||
return
|
return
|
||||||
|
except Exception as e:
|
||||||
|
logging.exception('Failed checking unmonitored files', e)
|
||||||
|
|
||||||
# Nothing else to be done
|
# Nothing else to be done
|
||||||
logging.info("/var/log is %d%% free." % pf)
|
logging.info("/var/log is %d%% free." % pf)
|
||||||
|
Loading…
Reference in New Issue
Block a user