Package ganeti :: Module daemon
[hide private]
[frames] | no frames]

Module daemon

source code

Module with helper classes and functions for daemons

Classes [hide private]
  SchedulerBreakout
Exception used to get out of the scheduler loop
  AsyncoreScheduler
Event scheduler integrated with asyncore
  GanetiBaseAsyncoreDispatcher
Base Ganeti Asyncore Dispacher
  AsyncStreamServer
A stream server to use with asyncore.
  AsyncTerminatedMessageStream
A terminator separated message stream asyncore module.
  AsyncUDPSocket
An improved asyncore udp socket.
  AsyncAwaker
A way to notify the asyncore loop that something is going on.
  _ShutdownCheck
Logic for Mainloop shutdown.
  Mainloop
Generic mainloop for daemons
Functions [hide private]
 
AsyncoreDelayFunction(timeout)
Asyncore-compatible scheduler delay function.
source code
 
_VerifyDaemonUser(daemon_name)
Verifies the process uid matches the configured uid.
source code
string
_BeautifyError(err)
Try to format an error better.
source code
 
_HandleSigHup(reopen_fn, signum, frame)
Handler for SIGHUP.
source code
 
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.
source code

Imports: asyncore, asynchat, collections, os, signal, logging, sched, time, socket, select, sys, utils, constants, errors, netutils, ssconf, runtime, compat


Function Details [hide private]

AsyncoreDelayFunction(timeout)

source code 

Asyncore-compatible scheduler delay function.

This is a delay function for sched that, rather than actually sleeping, executes asyncore events happening in the meantime.

After an event has occurred, rather than returning, it raises a SchedulerBreakout exception, which will force the current scheduler.run() invocation to terminate, so that we can also check for signals. The main loop will then call the scheduler run again, which will allow it to actually process any due events.

This is needed because scheduler.run() doesn't support a count=..., as asyncore loop, and the scheduler module documents throwing exceptions from inside the delay function as an allowed usage model.

_VerifyDaemonUser(daemon_name)

source code 

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_name - The 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

_BeautifyError(err)

source code 

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:
  • err - an exception object
Returns: string
the formatted error description

_HandleSigHup(reopen_fn, signum, frame)

source code 

Handler for SIGHUP.

Parameters:
  • reopen_fn - List of callback functions for reopening log files

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)

source code 

Shared main function for daemons.

Parameters:
  • daemon_name (string) - daemon name
  • optionparser (optparse.OptionParser) - initialized 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 (bool) - Whether the daemon uses threads
  • console_logging (boolean) - if True, the daemon will fall back to the system console if logging fails
  • default_ssl_cert (string) - Default SSL certificate path
  • default_ssl_key (string) - Default SSL key path
  • warn_breach (bool) - issue a warning at daemon launch time, before daemonizing, about the possibility of breaking parameter privacy invariants through the otherwise helpful debug logging.