diff --git a/liveMonitor.py b/liveMonitor.py index 076ed5c..08a66bb 100644 --- a/liveMonitor.py +++ b/liveMonitor.py @@ -6,13 +6,13 @@ from sendToLive import uploadOneEvent import datetime import logging -from RMS.Logger import initLogging import RMS.ConfigReader as cr from stat import ST_INO from uploadToArchive import readKeyFile, readIniFile +from ukmonPostProc import setupLogging -log = logging.getLogger("logger") +log = logging.getLogger() timetowait = 30 # seconds to wait for a new line before deciding the log is stale @@ -54,12 +54,11 @@ def monitorLogFile(camloc, rmscfg): """ cfg = cr.parse(os.path.expanduser(rmscfg)) - - log = logging.getLogger("logger") - while len(log.handlers) > 0: - log.removeHandler(log.handlers[0]) - - initLogging(cfg, 'ukmonlive_') + datadir = cfg.data_dir + logdir = os.path.expanduser(os.path.join(datadir, cfg.log_dir)) + + setupLogging(logdir, 'ukmonlive_') + log.info('--------------------------------') log.info(' live feed started') log.info('--------------------------------') @@ -79,8 +78,6 @@ def monitorLogFile(camloc, rmscfg): log.error('config file not present, aborting') exit(1) - datadir = cfg.data_dir - logdir = os.path.expanduser(os.path.join(datadir, cfg.log_dir)) keepon = True logf = '' capdir = '' diff --git a/refreshTools.sh b/refreshTools.sh index 8022feb..d76493d 100755 --- a/refreshTools.sh +++ b/refreshTools.sh @@ -44,7 +44,7 @@ if [[ "$LOCATION" != "NOTCONFIGURED" && "$LOCATION" != "" ]] ; then loopctr=0 echo "Checking RMS update not in progress" while [ $loopctr -lt 10 ] ; do - grep XX0001 $RMSCFG + grep XX0001 $RMSCFG | grep stationID: [ $? -eq 1 ] && break echo "RMS update in progress or station not configured, trying again in a minute" sleep 60 diff --git a/ukmonPostProc.py b/ukmonPostProc.py index 9fe69b4..6d67455 100644 --- a/ukmonPostProc.py +++ b/ukmonPostProc.py @@ -11,6 +11,8 @@ import os import sys +import glob +import time import Utils.BatchFFtoImage as bff2i import Utils.GenerateMP4s as gmp4 @@ -46,10 +48,22 @@ def setupLogging(logpath, prefix): log.addHandler(ch) log.setLevel(logging.INFO) + + purgeOldLogs(logdir, prefix) + log.info('logging initialised') return +def purgeOldLogs(logdir, logpref, days=30): + reftime = time.time() - 86400*days + for logf in glob.glob(os.path.join(logdir, logpref + '*.log*')): + if os.path.getmtime(logf) < reftime: + log.debug('removing old log', logf) + os.remove(logf) + return + + def rmsExternal(cap_dir, arch_dir, config): """ Called from RMS to trigger the UKMON specific code @@ -108,8 +122,9 @@ def rmsExternal(cap_dir, arch_dir, config): log.info('uploading remaining files to archive') uploadToArchive(arch_dir, keys=keys) - # do not remote reboot lock file if running another script + # do not remove reboot lock file if running another script # os.remove(rebootlockfile) + extrascrfn = os.path.join(myloc, 'extrascript') if os.path.isfile(extrascrfn): extrascript = open(extrascrfn,'r').readline().strip() @@ -129,6 +144,7 @@ def rmsExternal(cap_dir, arch_dir, config): log.info('unable to remove reboot lock file, pi will not reboot') pass + log.info('done') # clear log handlers again while len(log.handlers) > 0: log.removeHandler(log.handlers[0])