Skip to content
Snippets Groups Projects
Commit 8cabf472 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

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
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,7 @@ from ganeti import errors ...@@ -40,6 +40,7 @@ from ganeti import errors
from ganeti import netutils from ganeti import netutils
from ganeti import ssconf from ganeti import ssconf
from ganeti import runtime from ganeti import runtime
from ganeti import compat
class SchedulerBreakout(Exception): class SchedulerBreakout(Exception):
...@@ -539,6 +540,17 @@ def _BeautifyError(err): ...@@ -539,6 +540,17 @@ def _BeautifyError(err):
return "%s" % str(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, def GenericMain(daemon_name, optionparser,
check_fn, prepare_fn, exec_fn, check_fn, prepare_fn, exec_fn,
multithreaded=False, console_logging=False, multithreaded=False, console_logging=False,
...@@ -656,15 +668,20 @@ def GenericMain(daemon_name, optionparser, ...@@ -656,15 +668,20 @@ def GenericMain(daemon_name, optionparser,
else: else:
wpipe = None 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)) utils.WritePidFile(utils.DaemonPidFileName(daemon_name))
try: try:
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): if callable(prepare_fn):
prep_results = prepare_fn(options, args) prep_results = prepare_fn(options, args)
else: else:
......
...@@ -200,6 +200,8 @@ def SetupLogging(logfile, program, debug=0, stderr_logging=False, ...@@ -200,6 +200,8 @@ def SetupLogging(logfile, program, debug=0, stderr_logging=False,
@param root_logger: Root logger to use (for unittests) @param root_logger: Root logger to use (for unittests)
@raise EnvironmentError: if we can't open the log file and @raise EnvironmentError: if we can't open the log file and
syslog/stderr logging is disabled syslog/stderr logging is disabled
@rtype: callable
@return: Function reopening all open log files when called
""" """
progname = os.path.basename(program) progname = os.path.basename(program)
......
...@@ -172,3 +172,10 @@ would succeed. ...@@ -172,3 +172,10 @@ would succeed.
The option ``--priority`` sets the priority for opcodes submitted The option ``--priority`` sets the priority for opcodes submitted
by the command. 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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment