Commit 7a936509 authored by Rémi Duraffort's avatar Rémi Duraffort Committed by Senthil Kumaran Shanmugasundaram

Fix logrotation by using WatchedFileHandler

Change-Id: I88851d0423e0b4a679657650f9ccb0f592af1d1d
parent 0a2f84ce
......@@ -6,9 +6,4 @@
missingok
notifempty
create 644 root root
postrotate
if /etc/init.d/lava-slave status > /dev/null ; then \
/etc/init.d/lava-slave reload > /dev/null; \
fi;
endscript
}
......@@ -35,6 +35,7 @@ import atexit
import errno
import fcntl
import logging
import logging.handlers
import lzma
import os
import re
......@@ -377,7 +378,7 @@ def configure_logger(log_file, level):
if log_file == "-":
handler = logging.StreamHandler(sys.stdout)
else:
handler = logging.FileHandler(log_file, "a")
handler = logging.handlers.WatchedFileHandler(log_file)
handler.setFormatter(logging.Formatter(FORMAT))
LOG.addHandler(handler)
......@@ -619,16 +620,7 @@ def listen_to_master(master, jobs, poller, pipe_r, zmq_config, sock, timeout):
if sockets.get(pipe_r) == zmq.POLLIN:
signum = ord(os.read(pipe_r, 1))
if signum == signal.SIGHUP:
LOG.info("SIGHUP received, restarting loggers")
handler = LOG.handlers[0]
if isinstance(handler, logging.FileHandler):
# Keep the filename and remove the handler
log_file = handler.baseFilename
LOG.removeHandler(handler)
# Re-create the handler
handler = logging.FileHandler(log_file, "a")
handler.setFormatter(logging.Formatter(FORMAT))
LOG.addHandler(handler)
LOG.info("SIGHUP received, ignoring")
else:
LOG.info("Received a signal, leaving")
sys.exit(0)
......
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