Commit 8cabf472 authored by Michael Hanselmann's avatar Michael Hanselmann

Reopen log files upon SIGHUP in daemons

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 9a6813ac
......@@ -40,6 +40,7 @@ from ganeti import errors
from ganeti import netutils
from ganeti import ssconf
from ganeti import runtime
from ganeti import compat
class SchedulerBreakout(Exception):
......@@ -539,6 +540,17 @@ def _BeautifyError(err):
return "%s" % str(err)
def _HandleSigHup(reopen_cb, signum, frame): # pylint: disable-msg=W0613
"""Handler for SIGHUP.
@param reopen_cb: Callback function for reopening log files
"""
assert callable(reopen_cb)
logging.info("Reopening log files after receiving SIGHUP")
reopen_cb()
def GenericMain(daemon_name, optionparser,
check_fn, prepare_fn, exec_fn,
multithreaded=False, console_logging=False,
......@@ -656,15 +668,20 @@ def GenericMain(daemon_name, optionparser,
else:
wpipe = None
log_reopen_fn = \
utils.SetupLogging(constants.DAEMONS_LOGFILES[daemon_name], daemon_name,
debug=options.debug,
stderr_logging=not options.fork,
multithreaded=multithreaded,
syslog=options.syslog,
console_logging=console_logging)
# Reopen log file(s) on SIGHUP
signal.signal(signal.SIGHUP, compat.partial(_HandleSigHup, log_reopen_fn))
utils.WritePidFile(utils.DaemonPidFileName(daemon_name))
try:
try:
utils.SetupLogging(constants.DAEMONS_LOGFILES[daemon_name], daemon_name,
debug=options.debug,
stderr_logging=not options.fork,
multithreaded=multithreaded,
syslog=options.syslog,
console_logging=console_logging)
if callable(prepare_fn):
prep_results = prepare_fn(options, args)
else:
......
......@@ -200,6 +200,8 @@ def SetupLogging(logfile, program, debug=0, stderr_logging=False,
@param root_logger: Root logger to use (for unittests)
@raise EnvironmentError: if we can't open the log file and
syslog/stderr logging is disabled
@rtype: callable
@return: Function reopening all open log files when called
"""
progname = os.path.basename(program)
......
......@@ -172,3 +172,10 @@ would succeed.
The option ``--priority`` sets the priority for opcodes submitted
by the command.
Common daemon functionality
---------------------------
All Ganeti daemons re-open the log file(s) when sent a SIGHUP signal.
**logrotate**(8) can be used to rotate Ganeti's log files.
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