return "%s" % str(err)
-def _HandleSigHup(reopen_cb, signum, frame): # pylint: disable-msg=W0613
+def _HandleSigHup(reopen_fn, signum, frame): # pylint: disable-msg=W0613
"""Handler for SIGHUP.
- @param reopen_cb: Callback function for reopening log files
+ @param reopen_fn: List of callback functions for reopening log files
"""
- assert callable(reopen_cb)
logging.info("Reopening log files after receiving SIGHUP")
- reopen_cb()
+
+ for fn in reopen_fn:
+ if fn:
+ fn()
def GenericMain(daemon_name, optionparser,
if options.fork:
utils.CloseFDs()
- wpipe = utils.Daemonize(logfile=constants.DAEMONS_LOGFILES[daemon_name])
+ (wpipe, stdio_reopen_fn) = \
+ utils.Daemonize(logfile=constants.DAEMONS_LOGFILES[daemon_name])
else:
- wpipe = None
+ (wpipe, stdio_reopen_fn) = (None, None)
log_reopen_fn = \
utils.SetupLogging(constants.DAEMONS_LOGFILES[daemon_name], daemon_name,
console_logging=console_logging)
# Reopen log file(s) on SIGHUP
- signal.signal(signal.SIGHUP, compat.partial(_HandleSigHup, log_reopen_fn))
+ signal.signal(signal.SIGHUP,
+ compat.partial(_HandleSigHup, [log_reopen_fn, stdio_reopen_fn]))
utils.WritePidFile(utils.DaemonPidFileName(daemon_name))
try:
from ganeti import errors
from ganeti import constants
+from ganeti import compat
from ganeti.utils import retry as utils_retry
from ganeti.utils import wrapper as utils_wrapper
@type logfile: str
@param logfile: the logfile to which we should redirect stdout/stderr
- @rtype: int
- @return: the value zero
+ @rtype: tuple; (int, callable)
+ @return: File descriptor of pipe(2) which must be closed to notify parent
+ process and a callable to reopen log files
"""
# pylint: disable-msg=W0212
rcode = 0
os._exit(rcode) # Exit parent of the first child.
- SetupDaemonFDs(logfile, None)
- return wpipe
+ reopen_fn = compat.partial(SetupDaemonFDs, logfile, None)
+
+ # Open logs for the first time
+ reopen_fn()
+
+ return (wpipe, reopen_fn)
def KillProcess(pid, signal_=signal.SIGTERM, timeout=30,