module documentation

Module with helper classes and functions for daemons

Class AsyncAwaker A way to notify the asyncore loop that something is going on.
Class AsyncUDPSocket An improved asyncore udp socket.
Class GanetiBaseAsyncoreDispatcher Base Ganeti Asyncore Dispacher
Class Mainloop Generic mainloop for daemons
Function GenericMain Shared main function for daemons.
Class _ShutdownCheck Logic for Mainloop shutdown.
Function _BeautifyError Try to format an error better.
Function _HandleSigHup Handler for SIGHUP.
Function _VerifyDaemonUser Verifies the process uid matches the configured uid.
def GenericMain(daemon_name, optionparser, check_fn, prepare_fn, exec_fn, multithreaded=False, console_logging=False, default_ssl_cert=None, default_ssl_key=None, warn_breach=False):

Shared main function for daemons.

Parameters
daemon_name:stringdaemon name
optionparser:optparse.OptionParserinitialized optionparser with daemon-specific options (common -f -d options will be handled by this module)
check_fn:function which accepts (options, args)function that checks start conditions and exits if they're not met
prepare_fn:function which accepts (options, args)function that is run before forking, or None; it's result will be passed as the third parameter to exec_fn, or if None was passed in, we will just pass None to exec_fn
exec_fn:function which accepts (options, args, prepare_results)function that's executed with the daemon's pid file held, and runs the daemon itself.
multithreaded:boolWhether the daemon uses threads
console_logging:booleanif True, the daemon will fall back to the system console if logging fails
default_ssl_cert:stringDefault SSL certificate path
default_ssl_key:stringDefault SSL key path
warn_breach:boolissue a warning at daemon launch time, before daemonizing, about the possibility of breaking parameter privacy invariants through the otherwise helpful debug logging.
def _BeautifyError(err):

Try to format an error better.

Since we're dealing with daemon startup errors, in many cases this will be due to socket error and such, so we try to format these cases better.

Parameters
erran exception object
Returns
stringthe formatted error description
def _HandleSigHup(reopen_fn, signum, frame):

Handler for SIGHUP.

Parameters
reopen_fnList of callback functions for reopening log files
signumUndocumented
frameUndocumented
def _VerifyDaemonUser(daemon_name):

Verifies the process uid matches the configured uid.

This method verifies that a daemon is started as the user it is intended to be run

Parameters
daemon_nameThe name of daemon to be started
Returns
A tuple with the first item indicating success or not, the second item current uid and third with expected uid