![]() |
Kea
1.5.0
|
Base class for all services. More...
#include <daemon.h>
Inheritance diagram for isc::process::Daemon:Public Member Functions | |
| 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... | |
Static Public Member Functions | |
| 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 Member Functions | |
| virtual void | handleSignal () |
| Invokes handler for the next received signal. More... | |
| std::string | makePIDFileName () const |
| Manufacture the pid file name. More... | |
Protected Attributes | |
| 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... | |
Base class for all services.
This is the base class that all daemons (DHCPv4, DHCPv6, D2 and possibly others) are derived from. It provides a standard interface for starting up, reconfiguring, shutting down and several other operations. It also covers some common operations.
This class is not expected to be instantiated directly, but rather daemon implementations should derive from it.
Methods are not pure virtual, as we need to instantiate basic daemons (e.g. Dhcpv6Srv) in tests, without going through the hassles of implementing stub methods.
Classes derived from Daemon may install custom signal handlers using isc::util::SignalSet class. This base class provides a declaration of the SignalSet object that should be initialized in the derived classes to install the custom exception handlers.
| isc::process::Daemon::Daemon | ( | ) |
|
virtual |
| void isc::process::Daemon::checkConfigFile | ( | ) | const |
Checks the configuration file name.
| BadValue | when the configuration file name is bad. |
Definition at line 115 of file daemon.cc.
References isc_throw, and isc::util::Filename::name().
Referenced by isc::process::DControllerBase::launch().
Here is the call graph for this function:
|
virtual |
Performs final deconfiguration.
Performs configuration backend specific final clean-up. This is called shortly before the daemon terminates. Depending on backend, it may terminat existing msgq session, close LDAP connection or similar.
The daemon is not expected to receive any further commands or configuration updates as it is in final stages of shutdown.
Reimplemented in isc::dhcp::ControlledDhcpv4Srv, and isc::dhcp::ControlledDhcpv6Srv.
|
static |
Configures logger.
Applies configuration stored in "Logging" structure in the configuration file. This structure has a "loggers" array that contains 0 or more entries, each configuring one logging source (name, severity, debuglevel), each with zero or more outputs (file, maxsize, maximum number of files).
| log_config | JSON structures that describe logging |
| storage | configuration will be stored here |
Definition at line 66 of file daemon.cc.
References isc::process::LogConfigParser::parseConfiguration().
Referenced by isc::process::DControllerBase::configFromFile().
Here is the call graph for this function:| void isc::process::Daemon::createPIDFile | ( | int | pid = 0 | ) |
Creates the PID file.
If the PID file name has not been previously set, the method uses manufacturePIDFileName() to set it. If the PID file name refers to an existing file whose contents are a PID whose process is still alive, the method will throw a DaemonPIDExists exception. Otherwise, the file created (or truncated) and the given pid (if not zero) is written to the file.
| pid | PID to write to the file if not zero, otherwise the PID of the current process is used. |
Definition at line 203 of file daemon.cc.
References getPIDFileName(), isc_throw, makePIDFileName(), and setPIDFileName().
Referenced by isc::process::DControllerBase::launch().
Here is the call graph for this function:| std::string isc::process::Daemon::getConfigFile | ( | ) | const |
Returns config file name.
Definition at line 105 of file daemon.cc.
Referenced by isc::process::DControllerBase::checkConfigOnly(), isc::process::DControllerBase::configFromFile(), isc::process::DControllerBase::configWriteHandler(), and isc::process::DControllerBase::processSignal().
|
inlinestatic |
Returns default logger name.
Definition at line 208 of file daemon.h.
Referenced by isc::process::LoggingInfo::LoggingInfo().
| std::string isc::process::Daemon::getPIDFileDir | ( | ) | const |
| std::string isc::process::Daemon::getPIDFileName | ( | ) | const |
Returns the current PID file name.
Definition at line 150 of file daemon.cc.
Referenced by createPIDFile().
| std::string isc::process::Daemon::getProcName | ( | ) | const |
|
static |
Returns if running in verbose mode.
Definition at line 84 of file daemon.cc.
Referenced by isc::process::LoggingInfo::LoggingInfo().
|
static |
returns Kea version on stdout and exits.
With extended == false, this method returns a simple string containing version number. With extended == true, it returns also additional information about sources. It is expected to return extra information about dependencies and used DB backends.
As there is no static virtual methods in C++ this class method has to be redefined in derived classes and called with the derived class name or a child name.
| extended | print additional information? |
Definition at line 100 of file daemon.cc.
References isc_throw.
|
protectedvirtual |
Invokes handler for the next received signal.
This function provides a default implementation for the function handling next signal received by the process. It checks if a pointer to isc::util::SignalSet object and the signal handler function have been set. If they have been set, the signal handler is invoked for the the next signal registered in the SignalSet object.
This function should be received in the main loop of the process.
Definition at line 60 of file daemon.cc.
References signal_handler_, and signal_set_.
Referenced by isc::dhcp::Dhcpv6Srv::run_one(), and isc::dhcp::Dhcpv4Srv::run_one().
|
static |
Initializes logger.
This method initializes logging system. It also sets the default output to stdout. This is used in early stages of the startup phase before config file and parsed and proper logging details are known.
| log_name | name used in logger initialization |
| verbose | verbose mode (true usually enables DEBUG messages) |
Definition at line 88 of file daemon.cc.
References isc::log::DEBUG, isc::log::initLogger(), isc::log::MAX_DEBUG_LEVEL, and isc::log::setDefaultLoggingOutput().
Referenced by isc::process::DControllerBase::checkConfigOnly(), and isc::process::DControllerBase::launch().
Here is the call graph for this function:
|
protected |
Manufacture the pid file name.
Definition at line 174 of file daemon.cc.
References isc_throw, and isc::util::Filename::name().
Referenced by createPIDFile().
Here is the call graph for this function:| void isc::process::Daemon::setConfigFile | ( | const std::string & | config_file | ) |
Sets the configuration file name.
| config_file | pathname of the configuration file |
Definition at line 110 of file daemon.cc.
Referenced by isc::process::DControllerBase::parseArgs().
|
inlinestatic |
Sets the default logger name.
This name is used in cases when a user doesn't provide a configuration for logger in the Kea configuration file.
Definition at line 216 of file daemon.h.
References isc::asiodns::logger.
Referenced by isc::process::DControllerBase::checkConfigOnly(), and isc::process::DControllerBase::launch().
| void isc::process::Daemon::setPIDFileDir | ( | const std::string & | pid_file_dir | ) |
| void isc::process::Daemon::setPIDFileName | ( | const std::string & | pid_file_name | ) |
Sets PID file name.
If this method is called prior to calling createPIDFile, the value passed in will be treated as the full file name for the PID file. This provides a means to override the default file name with an explicit value.
| pid_file_name | file name to be used as the PID file |
Definition at line 159 of file daemon.cc.
References isc_throw.
Referenced by createPIDFile().
| void isc::process::Daemon::setProcName | ( | const std::string & | proc_name | ) |
Sets the process name.
| proc_name | name the process by which the process is recognized |
Definition at line 135 of file daemon.cc.
Referenced by isc::process::DControllerBase::launch().
|
static |
Sets or clears verbose mode.
Verbose mode (-v in command-line) triggers loggers to log everything (sets severity to DEBUG and debuglevel to 99). Values specified in the config file are ignored.
| verbose | specifies if verbose should be set or not |
Definition at line 79 of file daemon.cc.
Referenced by isc::process::DControllerBase::checkConfigOnly(), and isc::process::DControllerBase::launch().
|
virtual |
Initiates shutdown procedure for the whole DHCPv6 server.
Reimplemented in isc::dhcp::Dhcpv4Srv, isc::dhcp::Dhcpv6Srv, isc::dhcp::ControlledDhcpv4Srv, and isc::dhcp::ControlledDhcpv6Srv.
|
virtual |
Writes current configuration to specified file.
This method writes the current configuration to specified file.
If cfg is not specified, the current config (as returned by CfgMgr::instance().getCurrentCfg() will be returned.
| config_file | name of the file to write the configuration to |
| cfg | configuration to write (optional) |
| Unexpected | if CfgMgr can't retrieve configuration or file cannot be written |
Definition at line 229 of file daemon.cc.
References isc_throw, and isc::data::prettyPrint().
Referenced by isc::process::DControllerBase::configWriteHandler().
Here is the call graph for this function:
|
protected |
Pointer to the common signal handler invoked by the handleSignal function.
This pointer needs to be initialized to point to the signal handler function for signals being handled by the process. If signal handler it not initialized, the signals will not be handled.
Definition at line 246 of file daemon.h.
Referenced by handleSignal().
|
protected |
A pointer to the object installing custom signal handlers.
This pointer needs to be initialized to point to the SignalSet object in the derived classes which need to handle signals received by the process.
Definition at line 238 of file daemon.h.
Referenced by handleSignal(), isc::process::DControllerBase::initSignalHandling(), isc::dhcp::Dhcpv6Srv::run_one(), and isc::dhcp::Dhcpv4Srv::run_one().