Kea 2.7.5
isc::process::Daemon Class Reference

Base class for all services. More...

#include <daemon.h>

+ Inheritance diagram for isc::process::Daemon:

Public Member Functions

 Daemon ()
 Default constructor.
 
virtual ~Daemon ()
 Destructor.
 
void checkConfigFile () const
 Checks the configuration file name.
 
virtual void cleanup ()
 Performs final deconfiguration.
 
void createPIDFile (int pid=0)
 Creates the PID file.
 
std::string getConfigFile () const
 Returns config file name.
 
int getExitValue ()
 Fetches the exit value.
 
std::string getPIDFileDir () const
 Returns the directory used when forming default PID file name.
 
std::string getPIDFileName () const
 Returns the current PID file name.
 
virtual std::list< std::list< std::string > > jsonPathsToRedact () const
 Return a list of all paths that contain passwords or secrets.
 
isc::data::ConstElementPtr redactConfig (isc::data::ConstElementPtr const &config)
 Redact a configuration.
 
void setConfigFile (const std::string &config_file)
 Sets the configuration file name.
 
void setExitValue (int value)
 Sets the exit value.
 
void setPIDFileDir (const std::string &pid_file_dir)
 Sets the PID file directory.
 
void setPIDFileName (const std::string &pid_file_name)
 Sets PID file name.
 
virtual void shutdown ()
 Initiates shutdown procedure for the whole server.
 
virtual size_t writeConfigFile (const std::string &config_file, isc::data::ConstElementPtr cfg=isc::data::ConstElementPtr()) const
 Writes current configuration to specified file.
 

Static Public Member Functions

static void configureLogger (const isc::data::ConstElementPtr &log_config, const isc::process::ConfigPtr &storage)
 Configures logger.
 
static std::string getDefaultLoggerName ()
 Returns default logger name.
 
static std::string getProcName ()
 returns the process name This value is used as when forming the default PID file name
 
static bool getVerbose ()
 Returns if running in verbose mode.
 
static std::string getVersion (bool extended)
 returns Kea version on stdout and exits.
 
static void loggerInit (const char *log_name, bool verbose)
 Initializes logger.
 
static void setDefaultLoggerName (const std::string &logger)
 Sets the default logger name.
 
static void setProcName (const std::string &proc_name)
 Sets the process name.
 
static void setVerbose (const bool verbose)
 Sets or clears verbose mode.
 

Protected Member Functions

std::string makePIDFileName () const
 Manufacture the pid file name.
 

Protected Attributes

isc::asiolink::IOSignalSetPtr signal_set_
 A pointer to the object installing custom signal handlers.
 
boost::posix_time::ptime start_
 Timestamp of the start of the daemon.
 

Detailed Description

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. Dhcpv4Srv and Dhcpv6Srv) in tests, without going through the hassles of implementing stub methods.

Note
Only one instance of this class is instantiated as it encompasses the whole operation of the server. Nothing, however, enforces the singleton status of the object.

Definition at line 48 of file daemon.h.

Constructor & Destructor Documentation

◆ Daemon()

isc::process::Daemon::Daemon ( )

Default constructor.

Initializes the object installing custom signal handlers for the process to NULL.

Definition at line 41 of file daemon.cc.

◆ ~Daemon()

isc::process::Daemon::~Daemon ( )
virtual

Destructor.

Having virtual destructor ensures that all derived classes will have virtual destructor as well.

Definition at line 54 of file daemon.cc.

Member Function Documentation

◆ checkConfigFile()

void isc::process::Daemon::checkConfigFile ( ) const

Checks the configuration file name.

Exceptions
BadValuewhen the configuration file name is bad.

Definition at line 114 of file daemon.cc.

References isc_throw, and isc::util::file::Path::stem().

Referenced by isc::process::DControllerBase::launch().

+ Here is the call graph for this function:

◆ cleanup()

void isc::process::Daemon::cleanup ( )
virtual

Performs final deconfiguration.

Performs configuration backend specific final clean-up. This is called shortly before the daemon terminates. Depending on backend, it may terminate 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.

Definition at line 60 of file daemon.cc.

◆ configureLogger()

void isc::process::Daemon::configureLogger ( const isc::data::ConstElementPtr & log_config,
const isc::process::ConfigPtr & storage )
static

Configures logger.

Applies configuration stored in a top-level 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).

Parameters
log_configJSON structures that describe logging
storageconfiguration will be stored here

Definition at line 66 of file daemon.cc.

References isc::process::LogConfigParser::parseConfiguration().

Referenced by isc::process::DControllerBase::configFromFile(), isc::process::DControllerBase::configSetHandler(), and isc::process::DCfgMgrBase::simpleParseConfig().

+ Here is the call graph for this function:

◆ createPIDFile()

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.

Parameters
pidPID to write to the file if not zero, otherwise the PID of the current process is used.

Definition at line 202 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:

◆ getConfigFile()

std::string isc::process::Daemon::getConfigFile ( ) const

◆ getDefaultLoggerName()

static std::string isc::process::Daemon::getDefaultLoggerName ( )
inlinestatic

Returns default logger name.

Definition at line 207 of file daemon.h.

Referenced by isc::process::LoggingInfo::LoggingInfo().

◆ getExitValue()

int isc::process::Daemon::getExitValue ( )
inline

Fetches the exit value.

Definition at line 220 of file daemon.h.

Referenced by isc::process::DControllerBase::launch(), isc::dhcp::Dhcpv4Srv::run(), and isc::dhcp::Dhcpv6Srv::run().

◆ getPIDFileDir()

std::string isc::process::Daemon::getPIDFileDir ( ) const

Returns the directory used when forming default PID file name.

Returns
text string

Definition at line 139 of file daemon.cc.

◆ getPIDFileName()

std::string isc::process::Daemon::getPIDFileName ( ) const

Returns the current PID file name.

Returns
text string

Definition at line 149 of file daemon.cc.

Referenced by createPIDFile().

◆ getProcName()

std::string isc::process::Daemon::getProcName ( )
static

returns the process name This value is used as when forming the default PID file name

Returns
text string

Definition at line 129 of file daemon.cc.

Referenced by load(), and load().

◆ getVerbose()

bool isc::process::Daemon::getVerbose ( )
static

Returns if running in verbose mode.

Returns
verbose mode

Definition at line 84 of file daemon.cc.

Referenced by isc::process::LoggingInfo::LoggingInfo().

◆ getVersion()

std::string isc::process::Daemon::getVersion ( bool extended)
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.

Parameters
extendedprint additional information?
Returns
text string

Definition at line 99 of file daemon.cc.

References isc_throw.

◆ jsonPathsToRedact()

std::list< std::list< std::string > > isc::process::Daemon::jsonPathsToRedact ( ) const
virtual

Return a list of all paths that contain passwords or secrets.

Used in isc::process::Daemon::redactConfig to only make copies and only redact configuration subtrees that contain passwords or secrets. To be overridden by derived classes.

Returns
the list of lists of sequential JSON map keys needed to reach the passwords and secrets.

Reimplemented in isc::dhcp::Dhcpv4Srv, and isc::dhcp::Dhcpv6Srv.

Definition at line 253 of file daemon.cc.

Referenced by redactConfig().

◆ loggerInit()

void isc::process::Daemon::loggerInit ( const char * log_name,
bool verbose )
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.

Parameters
log_namename used in logger initialization
verboseverbose 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(), isc::process::DControllerBase::launch(), and main().

+ Here is the call graph for this function:

◆ makePIDFileName()

std::string isc::process::Daemon::makePIDFileName ( ) const
protected

Manufacture the pid file name.

Definition at line 173 of file daemon.cc.

References isc_throw, and isc::util::file::Path::stem().

Referenced by createPIDFile().

+ Here is the call graph for this function:

◆ redactConfig()

isc::data::ConstElementPtr isc::process::Daemon::redactConfig ( isc::data::ConstElementPtr const & config)

Redact a configuration.

Calls isc::process::redactConfig

Parameters
configthe Element tree structure that describes the configuration.
Returns
the redacted configuration

Definition at line 259 of file daemon.cc.

References jsonPathsToRedact(), and isc::process::redactConfig().

+ Here is the call graph for this function:

◆ setConfigFile()

void isc::process::Daemon::setConfigFile ( const std::string & config_file)

Sets the configuration file name.

Parameters
config_filepathname of the configuration file

Definition at line 109 of file daemon.cc.

Referenced by isc::process::DControllerBase::parseArgs().

◆ setDefaultLoggerName()

static void isc::process::Daemon::setDefaultLoggerName ( const std::string & logger)
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 215 of file daemon.h.

Referenced by isc::process::DControllerBase::checkConfigOnly(), isc::process::DControllerBase::launch(), and main().

◆ setExitValue()

void isc::process::Daemon::setExitValue ( int value)
inline

Sets the exit value.

Parameters
valuenew exit value.

Definition at line 227 of file daemon.h.

Referenced by isc::process::DControllerBase::shutdownHandler(), isc::dhcp::ControlledDhcpv4Srv::shutdownServer(), and isc::dhcp::ControlledDhcpv6Srv::shutdownServer().

◆ setPIDFileDir()

void isc::process::Daemon::setPIDFileDir ( const std::string & pid_file_dir)

Sets the PID file directory.

Parameters
pid_file_dirpath into which the PID file should be written Note the value should not include a trailing slash, '/'

Definition at line 144 of file daemon.cc.

◆ setPIDFileName()

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.

Parameters
pid_file_namefile name to be used as the PID file

Definition at line 158 of file daemon.cc.

References isc_throw.

Referenced by createPIDFile().

◆ setProcName()

void isc::process::Daemon::setProcName ( const std::string & proc_name)
static

Sets the process name.

Parameters
proc_namename the process by which the process is recognized

Definition at line 134 of file daemon.cc.

Referenced by isc::process::DControllerBase::launch().

◆ setVerbose()

void isc::process::Daemon::setVerbose ( const bool verbose)
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.

Parameters
verbosespecifies 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().

◆ shutdown()

void isc::process::Daemon::shutdown ( )
virtual

Initiates shutdown procedure for the whole server.

Reimplemented in isc::dhcp::Dhcpv4Srv, and isc::dhcp::Dhcpv6Srv.

Definition at line 63 of file daemon.cc.

◆ writeConfigFile()

size_t isc::process::Daemon::writeConfigFile ( const std::string & config_file,
isc::data::ConstElementPtr cfg = isc::data::ConstElementPtr() ) const
virtual

Writes current configuration to specified file.

This method writes the current configuration to specified file.

Todo
: this logically more belongs to CPL process file. Once Daemon is merged with CPL architecture, it will be a better fit.

If cfg is not specified, the current config (as returned by CfgMgr::instance().getCurrentCfg() will be returned.

Parameters
config_filename of the file to write the configuration to
cfgconfiguration to write (optional)
Returns
number of files written
Exceptions
Unexpectedif CfgMgr can't retrieve configuration or file cannot be written

Definition at line 228 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:

Member Data Documentation

◆ signal_set_

isc::asiolink::IOSignalSetPtr isc::process::Daemon::signal_set_
protected

A pointer to the object installing custom signal handlers.

This pointer needs to be initialized to point to the IOSignalSet object in the derived classes which need to handle signals received by the process.

Definition at line 257 of file daemon.h.

Referenced by isc::dhcp::ControlledDhcpv4Srv::cleanup(), isc::dhcp::ControlledDhcpv6Srv::cleanup(), isc::dhcp::ControlledDhcpv4Srv::init(), and isc::dhcp::ControlledDhcpv6Srv::init().

◆ start_

boost::posix_time::ptime isc::process::Daemon::start_
protected

The documentation for this class was generated from the following files: