![]() |
Kea
1.5.0
|
Application Controller. More...
#include <d_controller.h>
Inheritance diagram for isc::process::DControllerBase:Public Member Functions | |
| DControllerBase (const char *app_name, const char *bin_name) | |
| Constructor. More... | |
| virtual | ~DControllerBase () |
| Destructor. More... | |
| isc::data::ConstElementPtr | buildReportHandler (const std::string &command, isc::data::ConstElementPtr args) |
| handler for 'build-report' command More... | |
| virtual isc::data::ConstElementPtr | checkConfig (isc::data::ConstElementPtr new_config) |
| Instance method invoked by the configuration event handler and which processes the actual configuration check. More... | |
| virtual isc::data::ConstElementPtr | configFromFile () |
| Reconfigures the process from a configuration file. More... | |
| isc::data::ConstElementPtr | configGetHandler (const std::string &command, isc::data::ConstElementPtr args) |
| handler for config-get command More... | |
| isc::data::ConstElementPtr | configTestHandler (const std::string &command, isc::data::ConstElementPtr args) |
| handler for config-test command More... | |
| isc::data::ConstElementPtr | configWriteHandler (const std::string &command, isc::data::ConstElementPtr args) |
| handler for config-write command More... | |
| std::string | getAppName () const |
| Fetches the name of the application under control. More... | |
| std::string | getBinName () const |
| Fetches the name of the application executable. More... | |
| std::string | getVersion (bool extended) |
| returns Kea version on stdout and exit. More... | |
| virtual void | launch (int argc, char *argv[], const bool test_mode) |
| Acts as the primary entry point into the controller execution and provides the outermost application control logic: More... | |
| isc::data::ConstElementPtr | shutdownHandler (const std::string &command, isc::data::ConstElementPtr args) |
| handler for 'shutdown' command More... | |
| virtual isc::data::ConstElementPtr | updateConfig (isc::data::ConstElementPtr new_config) |
| Instance method invoked by the configuration event handler and which processes the actual configuration update. More... | |
| isc::data::ConstElementPtr | versionGetHandler (const std::string &command, isc::data::ConstElementPtr args) |
| handler for version-get command More... | |
Public Member Functions inherited from isc::process::Daemon | |
| Daemon () | |
| Default constructor. More... | |
| virtual | ~Daemon () |
| Destructor. More... | |
| void | checkConfigFile () const |
| Checks the configuration file name. More... | |
| virtual void | cleanup () |
| Performs final deconfiguration. More... | |
| void | createPIDFile (int pid=0) |
| Creates the PID file. More... | |
| std::string | getConfigFile () const |
| Returns config file name. More... | |
| std::string | getPIDFileDir () const |
| Returns the directory used when forming default PID file name. More... | |
| std::string | getPIDFileName () const |
| Returns the current PID file name. More... | |
| std::string | getProcName () const |
| returns the process name This value is used as when forming the default PID file name More... | |
| void | setConfigFile (const std::string &config_file) |
| Sets the configuration file name. More... | |
| void | setPIDFileDir (const std::string &pid_file_dir) |
| Sets the PID file directory. More... | |
| void | setPIDFileName (const std::string &pid_file_name) |
| Sets PID file name. More... | |
| void | setProcName (const std::string &proc_name) |
| Sets the process name. More... | |
| virtual void | shutdown () |
| Initiates shutdown procedure for the whole DHCPv6 server. More... | |
| virtual size_t | writeConfigFile (const std::string &config_file, isc::data::ConstElementPtr cfg=isc::data::ConstElementPtr()) const |
| Writes current configuration to specified file. More... | |
Protected Member Functions | |
| void | checkConfigOnly () |
| Check the configuration. More... | |
| virtual DProcessBase * | createProcess ()=0 |
| Abstract method that is responsible for instantiating the application process object. More... | |
| virtual bool | customOption (int option, char *optarg) |
| Virtual method that provides derivations the opportunity to support additional command line options. More... | |
| virtual const std::string | getCustomOpts () const |
| Virtual method which returns a string containing the option letters for any custom command line options supported by the derivation. More... | |
| asiolink::IOServicePtr & | getIOService () |
| Getter for fetching the controller's IOService. More... | |
| DProcessBasePtr | getProcess () |
| Fetches the current process. More... | |
| virtual const std::string | getUsageText () const |
| Virtual method which can be used to contribute derivation specific usage text. More... | |
| virtual std::string | getVersionAddendum () |
| Fetches text containing additional version specifics. More... | |
| void | initProcess () |
| Instantiates the application process and then initializes it. More... | |
| void | initSignalHandling () |
| Initializes signal handling. More... | |
| void | ioSignalHandler (IOSignalId sequence_id) |
| Handler for processing IOSignals. More... | |
| bool | isCheckOnly () const |
| Supplies whether or not check only mode is enabled. More... | |
| bool | isVerbose () const |
| Supplies whether or not verbose logging is enabled. More... | |
| bool | osSignalHandler (int signum) |
| Handler for processing OS-level signals. More... | |
| void | parseArgs (int argc, char *argv[]) |
| Processes the command line arguments. More... | |
| virtual isc::data::ConstElementPtr | parseFile (const std::string &file_name) |
| Parse a given file into Elements. More... | |
| virtual isc::data::ConstElementPtr | parseText (const std::string &input) |
| Parse text into Elements. More... | |
| virtual void | processSignal (int signum) |
| Application-level signal processing method. More... | |
| void | runProcess () |
| Invokes the application process's event loop,(DBaseProcess::run). More... | |
| void | setCheckOnly (bool value) |
| Method for enabling or disabling check only mode. More... | |
| void | setVerbose (bool value) |
| Method for enabling or disabling verbose logging. More... | |
| isc::data::ConstElementPtr | shutdownProcess (isc::data::ConstElementPtr args) |
| Initiates shutdown procedure. More... | |
| void | usage (const std::string &text) |
| Prints the program usage text to std error. More... | |
Protected Member Functions inherited from isc::process::Daemon | |
| virtual void | handleSignal () |
| Invokes handler for the next received signal. More... | |
| std::string | makePIDFileName () const |
| Manufacture the pid file name. More... | |
Static Protected Member Functions | |
| static DControllerBasePtr & | getController () |
| Static getter which returns the singleton instance. More... | |
| static void | setController (const DControllerBasePtr &controller) |
| Static setter which sets the singleton instance. More... | |
Friends | |
| class | DControllerTest |
Additional Inherited Members | |
Static Public Member Functions inherited from isc::process::Daemon | |
| static void | configureLogger (const isc::data::ConstElementPtr &log_config, const isc::process::ConfigPtr &storage) |
| Configures logger. More... | |
| static std::string | getDefaultLoggerName () |
| Returns default logger name. More... | |
| static bool | getVerbose () |
| Returns if running in verbose mode. More... | |
| static std::string | getVersion (bool extended) |
| returns Kea version on stdout and exits. More... | |
| static void | loggerInit (const char *log_name, bool verbose) |
| Initializes logger. More... | |
| static void | setDefaultLoggerName (const std::string &logger) |
| Sets the default logger name. More... | |
| static void | setVerbose (const bool verbose) |
| Sets or clears verbose mode. More... | |
Protected Attributes inherited from isc::process::Daemon | |
| isc::util::SignalHandler | signal_handler_ |
| Pointer to the common signal handler invoked by the handleSignal function. More... | |
| isc::util::SignalSetPtr | signal_set_ |
| A pointer to the object installing custom signal handlers. More... | |
Application Controller.
DControllerBase is an abstract singleton which provides the framework and services for managing an application process that implements the DProcessBase interface. It runs the process like a stand-alone, command line driven executable, which must be supplied a configuration file at startup. It coordinates command line argument parsing, process instantiation and initialization, and runtime control through external command and configuration event handling. It creates the IOService instance which is used for runtime control events and passes the IOService into the application process at process creation. It provides the callback handlers for command and configuration events which could be triggered by an external source. Such sources are intended to be registered with and monitored by the controller's IOService such that the appropriate handler can be invoked.
DControllerBase provides dynamic configuration file reloading upon receipt of SIGHUP, and graceful shutdown upon receipt of either SIGINT or SIGTERM.
NOTE: Derivations must supply their own static singleton instance method(s) for creating and fetching the instance. The base class declares the instance member in order for it to be available for static callback functions.
Definition at line 104 of file d_controller.h.
| isc::process::DControllerBase::DControllerBase | ( | const char * | app_name, |
| const char * | bin_name | ||
| ) |
Constructor.
| app_name | is display name of the application under control. This name appears in log statements. |
| bin_name | is the name of the application executable. |
Definition at line 31 of file d_controller.cc.
|
virtual |
Destructor.
Definition at line 674 of file d_controller.cc.
| ConstElementPtr isc::process::DControllerBase::buildReportHandler | ( | const std::string & | command, |
| isc::data::ConstElementPtr | args | ||
| ) |
handler for 'build-report' command
This method handles build-report command. It returns the output printed by configure script which contains most compilation parameters.
| command | (ignored) |
| args | (ignored) |
Definition at line 556 of file d_controller.cc.
References isc::config::createAnswer(), and isc::detail::getConfigReport().
Referenced by isc::agent::CtrlAgentController::registerCommands().
Here is the call graph for this function:
|
virtual |
Instance method invoked by the configuration event handler and which processes the actual configuration check.
Provides behavioral path for both integrated and stand-alone modes. The current implementation will merge the configuration update into the existing configuration and then invoke the application process' configure method with a final rollback.
| new_config | is the new configuration |
Definition at line 411 of file d_controller.cc.
Referenced by checkConfigOnly(), and configTestHandler().
|
protected |
Check the configuration.
Called by launch() when check_only_ mode is enabled
| VersionMessage | when successful but a message should be displayed |
| InvalidUsage | when an error was detected |
Definition at line 157 of file d_controller.cc.
References checkConfig(), getAppName(), isc::process::Daemon::getConfigFile(), initProcess(), isc_throw, isc::process::Daemon::loggerInit(), isc::config::parseAnswer(), parseFile(), isc::process::Daemon::setDefaultLoggerName(), isc::process::Daemon::setVerbose(), and isc::Exception::what().
Referenced by launch().
Here is the call graph for this function:
|
virtual |
Reconfigures the process from a configuration file.
By default the file is assumed to be a JSON text file whose contents include at least:
To translate the JSON content into Elements, parseFile() is called first. This virtual method provides derivations a means to parse the file content using an alternate parser. If it returns an empty pointer than the JSON parsing providing by Element::fromJSONFile() is called.
Once parsed, the method looks for the Element "Logging" and, if present uses it to configure logging.
It then extracts the set of configuration elements for the module-name that matches the controller's app_name_ and passes that set into updateConfig() (or checkConfig()).
The file may contain an arbitrary number of other modules.
Definition at line 322 of file d_controller.cc.
References isc::process::Daemon::configureLogger(), isc::config::createAnswer(), getAppName(), isc::process::Daemon::getConfigFile(), isc_throw, isc::config::parseAnswer(), parseFile(), and updateConfig().
Referenced by launch(), and processSignal().
Here is the call graph for this function:| ConstElementPtr isc::process::DControllerBase::configGetHandler | ( | const std::string & | command, |
| isc::data::ConstElementPtr | args | ||
| ) |
handler for config-get command
This method handles the config-get command, which retrieves the current configuration and returns it in response.
| command | (ignored) |
| args | (ignored) |
Definition at line 416 of file d_controller.cc.
References isc::config::createAnswer().
Referenced by isc::agent::CtrlAgentController::registerCommands().
Here is the call graph for this function:| ConstElementPtr isc::process::DControllerBase::configTestHandler | ( | const std::string & | command, |
| isc::data::ConstElementPtr | args | ||
| ) |
handler for config-test command
This method handles the config-test command, which checks configuration specified in args parameter.
| command | (ignored) |
| args | configuration to be checked. |
Definition at line 505 of file d_controller.cc.
References checkConfig(), isc::config::createAnswer(), and getAppName().
Referenced by isc::agent::CtrlAgentController::registerCommands().
Here is the call graph for this function:| ConstElementPtr isc::process::DControllerBase::configWriteHandler | ( | const std::string & | command, |
| isc::data::ConstElementPtr | args | ||
| ) |
handler for config-write command
This handle processes write-config command, which writes the current configuration to disk. This command takes one optional parameter called filename. If specified, the current configuration will be written to that file. If not specified, the file used during Kea start-up will be used. To avoid any exploits, the path is always relative and .. is not allowed in the filename. This is a security measure against exploiting file writes remotely.
| command | (ignored) |
| args | may contain optional string argument filename |
Definition at line 424 of file d_controller.cc.
References isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::process::Daemon::getConfigFile(), isc::Exception::what(), and isc::process::Daemon::writeConfigFile().
Referenced by isc::agent::CtrlAgentController::registerCommands().
Here is the call graph for this function:
|
protectedpure virtual |
Abstract method that is responsible for instantiating the application process object.
It is invoked by the controller after command line argument parsing as part of the process initialization (see initProcess method).
Referenced by initProcess().
|
protectedvirtual |
Virtual method that provides derivations the opportunity to support additional command line options.
It is invoked during command line argument parsing (see parseArgs method) if the option is not recognized as a stock DControllerBase option.
| option | is the option "character" from the command line, without any prefixing hyphen(s) |
| optarg | is the argument value (if one) associated with the option |
Definition at line 292 of file d_controller.cc.
Referenced by parseArgs().
|
inline |
Fetches the name of the application under control.
Definition at line 224 of file d_controller.h.
Referenced by checkConfigOnly(), configFromFile(), and configTestHandler().
|
inline |
Fetches the name of the application executable.
Definition at line 231 of file d_controller.h.
|
inlinestaticprotected |
Static getter which returns the singleton instance.
Definition at line 420 of file d_controller.h.
|
inlineprotectedvirtual |
Virtual method which returns a string containing the option letters for any custom command line options supported by the derivation.
These are added to the stock options of "c", "d", ..., during command line interpretation.
Definition at line 350 of file d_controller.h.
Referenced by parseArgs().
|
inlineprotected |
Getter for fetching the controller's IOService.
Definition at line 412 of file d_controller.h.
|
inlineprotected |
Fetches the current process.
Definition at line 565 of file d_controller.h.
Referenced by isc::agent::CtrlAgentController::getCtrlAgentProcess(), and isc::netconf::NetconfController::getNetconfProcess().
|
inlineprotectedvirtual |
Virtual method which can be used to contribute derivation specific usage text.
It is invoked by the usage() method under invalid usage conditions.
Definition at line 340 of file d_controller.h.
Referenced by usage().
| std::string isc::process::DControllerBase::getVersion | ( | bool | extended | ) |
returns Kea version on stdout and exit.
redeclaration/redefinition. isc::process::Daemon::getVersion()
Definition at line 681 of file d_controller.cc.
References isc::log::Logger::getVersion(), and getVersionAddendum().
Referenced by parseArgs(), and versionGetHandler().
Here is the call graph for this function:
|
inlineprotectedvirtual |
Fetches text containing additional version specifics.
This method is provided so derivations can append any additional desired information such as library dependencies to the extended version text returned when DControllerBase::getVersion(true) is invoked.
Reimplemented in isc::d2::D2Controller.
Definition at line 582 of file d_controller.h.
Referenced by getVersion().
|
protected |
Instantiates the application process and then initializes it.
This is the second step taken during launch, following successful command line parsing. It is used to invoke the derivation-specific implementation of createProcess, following by an invoking of the newly instantiated process's init method.
| throws | DControllerBaseError or indirectly DProcessBaseError if there is a failure creating or initializing the application process. |
Definition at line 299 of file d_controller.cc.
References createProcess(), isc::log::DBGLVL_START_SHUT, isc::process::dctl_logger, isc_throw, LOG_DEBUG, and isc::Exception::what().
Referenced by checkConfigOnly(), and launch().
Here is the call graph for this function:
|
protected |
Initializes signal handling.
This method configures the controller to catch and handle signals. It instantiates an IOSignalQueue, registers osSignalHandler() as the SignalSet "on-receipt" handler, and lastly instantiates a SignalSet which listens for SIGHUP, SIGINT, and SIGTERM.
Definition at line 582 of file d_controller.cc.
References osSignalHandler(), isc::util::SignalSet::setOnReceiptHandler(), and isc::process::Daemon::signal_set_.
Referenced by launch().
Here is the call graph for this function:
|
protected |
Handler for processing IOSignals.
This method is supplied as the callback when IOSignals are scheduled. It fetches the IOSignal for the given sequence_id and then invokes the virtual method, processSignal() passing it the signal value obtained from the IOSignal. This allows derivations to supply a custom signal processing method, while ensuring IOSignalQueue integrity.
| sequence_id | id of the IOSignal instance "received" |
Definition at line 606 of file d_controller.cc.
References processSignal().
Referenced by osSignalHandler().
Here is the call graph for this function:
|
inlineprotected |
Supplies whether or not check only mode is enabled.
Definition at line 396 of file d_controller.h.
Referenced by launch().
|
inlineprotected |
Supplies whether or not verbose logging is enabled.
Definition at line 382 of file d_controller.h.
|
virtual |
Acts as the primary entry point into the controller execution and provides the outermost application control logic:
It is intended to be called from main() and be given the command line arguments.
This function can be run in "test mode". It prevents initialization of module logger. This is used in unit tests which initialize logger in their main function. Such a logger uses environmental variables to control severity, verbosity etc.
| argc | is the number of command line arguments supplied |
| argv | is the array of string (char *) command line arguments |
| test_mode | is a bool value which indicates if DControllerBase::launch should be run in the test mode (if true). This parameter doesn't have default value to force test implementers to enable test mode explicitly. |
| throws | one of the following exceptions: InvalidUsage - Indicates invalid command line. ProcessInitError - Failed to create and initialize application process object. ProcessRunError - A fatal error occurred while in the application process event loop. |
Definition at line 57 of file d_controller.cc.
References isc::process::Daemon::checkConfigFile(), checkConfigOnly(), configFromFile(), isc::process::Daemon::createPIDFile(), isc::log::DBGLVL_START_SHUT, isc::process::dctl_logger, initProcess(), initSignalHandling(), isc_throw, isCheckOnly(), LOG_DEBUG, LOG_FATAL, LOG_INFO, isc::process::Daemon::loggerInit(), isc::config::parseAnswer(), parseArgs(), runProcess(), isc::process::Daemon::setDefaultLoggerName(), isc::process::Daemon::setProcName(), isc::process::Daemon::setVerbose(), usage(), and isc::Exception::what().
Here is the call graph for this function:
|
protected |
Handler for processing OS-level signals.
This method is installed as the SignalSet "on-receipt" handler. Upon invocation, it uses the controller's IOSignalQueue to schedule an IOSignal with for the given signal value.
| signum | OS signal value (e.g. SIGINT, SIGUSR1 ...) to received |
Definition at line 597 of file d_controller.cc.
References ioSignalHandler().
Referenced by initSignalHandling().
Here is the call graph for this function:
|
protected |
Processes the command line arguments.
It is the first step taken after the controller has been launched. It combines the stock list of options with those returned by getCustomOpts(), and uses cstdlib's getopt to loop through the command line. It handles stock options directly, and passes any custom options into the customOption method. Currently there are only some stock options -c/t for specifying the configuration file, -d for verbose logging, and -v/V/W for version reports.
| argc | is the number of command line arguments supplied |
| argv | is the array of string (char *) command line arguments |
| InvalidUsage | when there are usage errors. |
| VersionMessage | if the -v, -V or -W arguments is given. |
Definition at line 211 of file d_controller.cc.
References customOption(), isc::detail::getConfigReport(), getCustomOpts(), getVersion(), isc_throw, and isc::process::Daemon::setConfigFile().
Referenced by launch().
Here is the call graph for this function:
|
protectedvirtual |
Parse a given file into Elements.
This method provides a means for deriving classes to use alternate parsing mechanisms to parse configuration files into the corresponding isc::data::Elements. The elements produced must be equivalent to those which would be produced by the original JSON parsing. Implementations should throw when encountering errors.
The default implementation returns an empty pointer, signifying to callers that they should submit the file to the original parser.
| file_name | pathname of the file to parse |
Reimplemented in isc::agent::CtrlAgentController, and isc::netconf::NetconfController.
Definition at line 51 of file d_controller.cc.
Referenced by checkConfigOnly(), and configFromFile().
|
inlineprotectedvirtual |
Parse text into Elements.
This method provides a means for deriving classes to use alternate parsing mechanisms to parse configuration text into the corresponding isc::data::Elements. The elements produced must be equivalent to those which would be produced by the original JSON parsing. Implementations should throw when encountering errors.
The default implementation returns an empty pointer, signifying to callers that they should submit the text to the original parser.
| input | text to parse |
Definition at line 481 of file d_controller.h.
|
protectedvirtual |
Application-level signal processing method.
This method is the last step in processing a OS signal occurrence. It is invoked when an IOSignal's internal timer callback is executed by IOService. It currently supports the following signals as follows:
Reimplemented in isc::netconf::NetconfController.
Definition at line 619 of file d_controller.cc.
References configFromFile(), isc::log::DBGLVL_START_SHUT, isc::process::dctl_logger, isc::process::Daemon::getConfigFile(), LOG_DEBUG, LOG_ERROR, LOG_INFO, LOG_WARN, isc::config::parseAnswer(), and shutdownHandler().
Referenced by ioSignalHandler(), and isc::netconf::NetconfController::processSignal().
Here is the call graph for this function:
|
protected |
Invokes the application process's event loop,(DBaseProcess::run).
It is called during launch only after successfully completing the requested setup: command line parsing, application initialization, and session establishment (if not stand-alone). The process event loop is expected to only return upon application shutdown either in response to the shutdown command or due to an unrecoverable error.
Definition at line 390 of file d_controller.cc.
References isc::log::DBGLVL_START_SHUT, isc::process::dctl_logger, isc_throw, and LOG_DEBUG.
Referenced by launch().
|
inlineprotected |
Method for enabling or disabling check only mode.
setVerbose are currently not used.| value | is the new value to assign the flag. |
Definition at line 405 of file d_controller.h.
|
staticprotected |
Static setter which sets the singleton instance.
| controller | is a pointer to the singleton instance. |
| throws | DControllerBase error if an attempt is made to set the instance a second time. |
Definition at line 39 of file d_controller.cc.
References isc_throw.
|
inlineprotected |
Method for enabling or disabling verbose logging.
| value | is the new value to assign the flag. |
Definition at line 389 of file d_controller.h.
| ConstElementPtr isc::process::DControllerBase::shutdownHandler | ( | const std::string & | command, |
| isc::data::ConstElementPtr | args | ||
| ) |
handler for 'shutdown' command
This method handles shutdown command. It initiates the shutdown procedure using CPL methods.
| command | (ignored) |
| args | (ignored) |
Definition at line 561 of file d_controller.cc.
References shutdownProcess().
Referenced by processSignal(), and isc::agent::CtrlAgentController::registerCommands().
Here is the call graph for this function:
|
protected |
Initiates shutdown procedure.
This method is invoked by executeCommand in response to the shutdown command. It will invoke the application process's shutdown method which causes the process to to begin its shutdown process.
Note, it is assumed that the process of shutting down is neither instantaneous nor synchronous. This method does not "block" waiting until the process has halted. Rather it is used to convey the need to shutdown. A successful return indicates that the shutdown has successfully commenced, but does not indicate that the process has actually exited.
| args | is a set of derivation-specific arguments (if any) for the shutdown command. |
Definition at line 570 of file d_controller.cc.
References isc::config::createAnswer(), isc::process::dctl_logger, and LOG_WARN.
Referenced by shutdownHandler().
Here is the call graph for this function:
|
virtual |
Instance method invoked by the configuration event handler and which processes the actual configuration update.
Provides behavioral path for both integrated and stand-alone modes. The current implementation will merge the configuration update into the existing configuration and then invoke the application process' configure method.
| new_config | is the new configuration |
Definition at line 405 of file d_controller.cc.
Referenced by configFromFile().
|
protected |
Prints the program usage text to std error.
| text | is a string message which will preceded the usage text. This is intended to be used for specific usage violation messages. |
Definition at line 652 of file d_controller.cc.
References getUsageText().
Referenced by launch().
Here is the call graph for this function:| ConstElementPtr isc::process::DControllerBase::versionGetHandler | ( | const std::string & | command, |
| isc::data::ConstElementPtr | args | ||
| ) |
handler for version-get command
This method handles the version-get command. It returns the basic and extended version.
| command | (ignored) |
| args | (ignored) |
Definition at line 544 of file d_controller.cc.
References isc::config::createAnswer(), and getVersion().
Referenced by isc::agent::CtrlAgentController::registerCommands().
Here is the call graph for this function:
|
friend |
Definition at line 619 of file d_controller.h.