24#include <kea_version.h> 
   36namespace ph = std::placeholders;
 
   45    : app_name_(app_name), bin_name_(bin_name),
 
   46      verbose_(false), check_only_(false),
 
 
   59    controller_ = controller;
 
 
   84        return (EXIT_SUCCESS);
 
  106    } 
catch (
const std::exception& ex) {
 
  108            .arg(app_name_).arg(ex.
what());
 
  116                  .arg(bin_name_).arg(ex.
what());
 
  118    } 
catch (
const std::exception& ex) {
 
  120                  .arg(app_name_).arg(ex.
what());
 
  129        .arg(PACKAGE_VERSION_TYPE);
 
  132    if (std::string(PACKAGE_VERSION_TYPE) == 
"development") {
 
  144    } 
catch (
const std::exception& ex) {
 
  146                  .arg(app_name_).arg(ex.
what());
 
  148                  "Application Process initialization failed: " << ex.
what());
 
  159                  .arg(app_name_).arg(comment->stringValue());
 
  161                  << comment->stringValue());
 
  165    start_ = boost::posix_time::second_clock::universal_time();
 
  173    } 
catch (
const std::exception& ex) {
 
  175                  .arg(app_name_).arg(ex.
what());
 
  177                  "Application process event loop failed: " << ex.
what());
 
  182        .arg(app_name_).arg(getpid()).arg(VERSION);
 
 
  193        setenv(
"KEA_LOCKFILE_DIR", 
"none", 0);
 
  200        if (config_file.empty()) {
 
  210            std::cerr << 
"Syntax check OK" << std::endl;
 
  215        module_config = whole_config->get(
getAppName());
 
  216        if (!module_config) {
 
  218                      " does not include '" << 
getAppName() << 
"' entry");
 
  222                      " includes not map '" << 
getAppName() << 
"' entry");
 
  227        if (!errmsg.empty()) {
 
  239                      << answer->stringValue());
 
  245    } 
catch (
const std::exception& ex) {
 
 
  268    ExhaustOptions e(argc, argv, opts);
 
  270    while ((ch = getopt(argc, argv, opts.c_str())) != -1) {
 
  298            if (optarg == NULL) {
 
  314            char const saved_optopt(optopt);
 
  315            std::string 
const saved_optarg(optarg ? optarg : std::string());
 
  319                      (saved_optarg.empty() ? std::string() : 
" " + saved_optarg));
 
  327                char const saved_optopt(optopt);
 
  328                std::string 
const saved_optarg(optarg ? optarg : std::string());
 
  332                          (saved_optarg.empty() ? std::string() : 
" " + saved_optarg));
 
 
  358    } 
catch (
const std::exception& ex) {
 
 
  386        if (config_file.empty()) {
 
  389                                "use -c command line option.");
 
  401        module_config = whole_config->get(
getAppName());
 
  402        if (!module_config) {
 
  404                                " does not include '" <<
 
  409                      " includes not map '" << 
getAppName() << 
"' entry");
 
  414        if (!errmsg.empty()) {
 
  430        storage->applyLoggingCfg();
 
  434        process_->getCfgMgr()->getContext()->applyLoggingCfg();
 
  435    } 
catch (
const std::exception& ex) {
 
  437        process_->getCfgMgr()->getContext()->applyLoggingCfg();
 
  441                 std::string(
"Configuration parsing failed: ") + ex.what());
 
 
  465    return (process_->configure(new_config, 
false));
 
 
  471    return (process_->configure(new_config, 
true));
 
 
  497    std::string filename;
 
  504        if (filename_param) {
 
  507                                     "passed parameter 'filename' " 
  510            filename = filename_param->stringValue();
 
  514    if (filename.empty()) {
 
  518        if (filename.empty()) {
 
  520                                 "Unable to determine filename." 
  521                                 "Please specify filename explicitly."));
 
  527            std::ostringstream msg;
 
  528            msg << 
"not allowed to write config into " << filename
 
  529                << 
": " << ex.
what();
 
  538        ElementPtr cfg = process_->getCfgMgr()->getContext()->toElement();
 
  542                             std::string(
"Error during config-write:")
 
  547                             "Error writing configuration to " + filename));
 
  556                         + filename + 
" successful", params));
 
 
  564    for (
auto const& obj : args->mapValue()) {
 
  565        const std::string& obj_name = obj.first;
 
  566        if (obj_name == app_name) {
 
  570            .arg(
"'" + obj_name + 
"', defining anything in global level besides '" 
  571                 + app_name + 
"' is no longer supported.");
 
  572        if (errmsg.empty()) {
 
  573            errmsg = 
" contains unsupported '" + obj_name + 
"' parameter";
 
  575            errmsg += 
" (and '" + obj_name + 
"')";
 
 
  591        message = 
"Missing mandatory 'arguments' parameter.";
 
  593        module_config = args->get(app_name);
 
  594        if (!module_config) {
 
  595            message = 
"Missing mandatory '" + app_name + 
"' parameter.";
 
  597            message = 
"'" + app_name + 
"' parameter expected to be a map.";
 
  601    if (message.empty()) {
 
  604        if (!errmsg.empty()) {
 
  605            message = 
"'arguments' parameter" + errmsg;
 
  609    if (!message.empty()) {
 
 
  642        message = 
"Missing mandatory 'arguments' parameter.";
 
  644        module_config = args->get(app_name);
 
  645        if (!module_config) {
 
  646            message = 
"Missing mandatory '" + app_name + 
"' parameter.";
 
  648            message = 
"'" + app_name + 
"' parameter expected to be a map.";
 
  652    if (!message.empty()) {
 
  679        storage->applyLoggingCfg();
 
  685        process_->getCfgMgr()->getContext()->applyLoggingCfg();
 
  687    } 
catch (
const std::exception& ex) {
 
  689        process_->getCfgMgr()->getContext()->applyLoggingCfg();
 
  693                 std::string(
"Configuration parsing failed: ") + ex.what());
 
 
  700    const std::string& tag = process_->getCfgMgr()->getContext()->getServerTag();
 
 
  712    auto now = boost::posix_time::second_clock::universal_time();
 
  713    if (!
start_.is_not_a_date_time()) {
 
  714        auto uptime = now - 
start_;
 
  718    auto last_commit = process_->getCfgMgr()->getContext()->getLastCommitTime();
 
  719    if (!last_commit.is_not_a_date_time()) {
 
  720        auto reload = now - last_commit;
 
 
  734    arguments->set(
"extended", extended);
 
 
  751    int exit_value = EXIT_SUCCESS;
 
  762                                     "parameter 'exit-value' is not an integer"));
 
  765            exit_value = param->intValue();
 
 
  776        return (process_->shutdown(args));
 
 
  795    io_signal_set_->add(SIGHUP);
 
  796    io_signal_set_->add(SIGINT);
 
  797    io_signal_set_->add(SIGTERM);
 
 
  811                          .arg(comment->stringValue());
 
 
  836        std::cerr << 
"Usage error: " << text << std::endl;
 
  839    std::cerr << 
"Usage: " << bin_name_ << std::endl
 
  840              << 
"  -v: print version number and exit" << std::endl
 
  841              << 
"  -V: print extended version information and exit" 
  843              << 
"  -W: display the configuration report and exit" 
  845              << 
"  -d: optional, verbose output " << std::endl
 
  846              << 
"  -c <config file name> : mandatory," 
  847              << 
" specify name of configuration file" << std::endl
 
  848              << 
"  -t <config file name> : check the" 
  849              << 
" configuration file and exit" << std::endl
 
  850              << 
"  -X: disables security restrictions" << std::endl;
 
 
  862        if (!names.empty()) {
 
  864            for (
size_t i = 1; i < names.size(); ++i) {
 
  865                msg += std::string(
", ") + names[i];
 
  873    io_signal_set_.reset();
 
 
  884    std::stringstream tmp;
 
  888        tmp << 
" (" << EXTENDED_VERSION << 
")" << std::endl;
 
  889        tmp << 
"premium: " << PREMIUM_EXTENDED_VERSION << std::endl;
 
  890        tmp << 
"linked with:" << std::endl;
 
 
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr fromJSONFile(const std::string &file_name, bool preproc=false)
Reads contents of specified file and interprets it as JSON.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void clearIOServices()
Clear the list of IOService objects.
static IOServiceMgr & instance()
Access the IOServiceMgr singleton instance.
The IOService class is a wrapper for the ASIO io_context class.
Implements an asynchronous "signal" for IOService driven processing.
static std::string getHash(const isc::data::ConstElementPtr &config)
returns a hash of a given Element structure
static std::string getVersion()
Get version string.
static std::vector< std::string > getLibraryNames()
Return list of loaded libraries.
static bool unloadLibraries()
Unload libraries.
static void prepareUnloadLibraries()
Prepare the unloading of libraries.
static std::string getVersion()
Version.
Base class for all configurations.
Exception thrown when the controller encounters an operational error.
isc::data::ConstElementPtr configReloadHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-reload command
isc::data::ConstElementPtr buildReportHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for 'build-report' command
void runProcess()
Invokes the application process's event loop,(DBaseProcess::run).
void initProcess()
Instantiates the application process and then initializes it.
isc::data::ConstElementPtr statusGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for status-get command
void usage(const std::string &text)
Prints the program usage text to std error.
asiolink::IOServicePtr & getIOService()
Getter for fetching the controller's IOService.
isc::data::ConstElementPtr shutdownProcess(isc::data::ConstElementPtr args)
Initiates shutdown procedure.
virtual const std::string getCustomOpts() const
Virtual method which returns a string containing the option letters for any custom command line optio...
virtual void processSignal(int signum)
Application-level signal processing method.
virtual ~DControllerBase()
Destructor.
isc::data::ConstElementPtr configWriteHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-write command
static void setController(const DControllerBasePtr &controller)
Static setter which sets the singleton instance.
std::string handleOtherObjects(isc::data::ConstElementPtr args)
Deals with other (i.e.
isc::data::ConstElementPtr versionGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for version-get command
isc::data::ConstElementPtr configSetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-set command
void initSignalHandling()
Initializes signal handling.
virtual const std::string getUsageText() const
Virtual method which can be used to contribute derivation specific usage text.
virtual isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr new_config)
Instance method invoked by the configuration event handler and which processes the actual configurati...
virtual DProcessBase * createProcess()=0
Abstract method that is responsible for instantiating the application process object.
bool isCheckOnly() const
Supplies whether or not check only mode is enabled.
isc::data::ConstElementPtr configGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-get command
virtual int launch(int argc, char *argv[], const bool test_mode)
Acts as the primary entry point into the controller execution and provides the outermost application ...
void parseArgs(int argc, char *argv[])
Processes the command line arguments.
virtual bool customOption(int option, char *optarg)
Virtual method that provides derivations the opportunity to support additional command line options.
isc::data::ConstElementPtr configHashGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-hash-get command
isc::data::ConstElementPtr configTestHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-test command
isc::data::ConstElementPtr serverTagGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for server-tag-get command
std::string getAppName() const
Fetches the name of the application under control.
virtual isc::data::ConstElementPtr parseFile(const std::string &file_name)
Parse a given file into Elements.
virtual isc::data::ConstElementPtr configFromFile()
Reconfigures the process from a configuration file.
std::string getVersion(bool extended)
returns Kea version on stdout and exit.
DControllerBase(const char *app_name, const char *bin_name)
Constructor.
virtual isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr new_config)
Instance method invoked by the configuration event handler and which processes the actual configurati...
void checkConfigOnly()
Check the configuration.
isc::data::ConstElementPtr shutdownHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for 'shutdown' command
Exception thrown when the PID file points to a live PID.
std::string getConfigFile() const
Returns config file name.
virtual size_t writeConfigFile(const std::string &config_file, isc::data::ConstElementPtr cfg=isc::data::ConstElementPtr()) const
Writes current configuration to specified file.
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
static void configureLogger(const isc::data::ConstElementPtr &log_config, const isc::process::ConfigPtr &storage)
Configures logger.
boost::posix_time::ptime start_
Timestamp of the start of the daemon.
static void loggerInit(const char *log_name, bool verbose)
Initializes logger.
void checkWriteConfigFile(std::string &file)
Checks the to-be-written configuration file name.
void setExitValue(int value)
Sets the exit value.
void checkConfigFile() const
Checks the configuration file name.
static void setDefaultLoggerName(const std::string &logger)
Sets the default logger name.
static void setProcName(const std::string &proc_name)
Sets the process name.
int getExitValue()
Fetches the exit value.
void createPIDFile(int pid=0)
Creates the PID file.
void setConfigFile(const std::string &config_file)
Sets the configuration file name.
Exception thrown when the command line is invalid.
Exception thrown when the controller launch fails.
Exception thrown when the application process fails.
Exception thrown when the application process encounters an operation in its event loop (i....
Exception used to convey version info upwards.
static void enableEnforcement(bool enable)
Enables or disables security enforcment checks.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Logging initialization functions.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
A wrapper interface for the ASIO library.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Parses a standard config/command level answer and returns arguments or text status code.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
std::string getConfigReport()
const int DBGLVL_START_SHUT
This is given a value of 0 as that is the level selected if debugging is enabled without giving a lev...
isc::log::Logger dctl_logger("dctl")
Defines the logger used within libkea-process library.
const isc::log::MessageID DCTL_ROOT_USER_SECURITY_WARNING
const isc::log::MessageID DCTL_DEVELOPMENT_VERSION
const isc::log::MessageID DCTL_SHUTDOWN
const isc::log::MessageID DCTL_CFG_FILE_RELOAD_ERROR
const isc::log::MessageID DCTL_CFG_FILE_RELOAD_SIGNAL_RECVD
const isc::log::MessageID DCTL_RUN_PROCESS
const isc::log::MessageID DCTL_STANDALONE
const isc::log::MessageID DCTL_PID_FILE_ERROR
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the ConfigBase.
boost::shared_ptr< DControllerBase > DControllerBasePtr
const isc::log::MessageID DCTL_UNLOAD_LIBRARIES_ERROR
const isc::log::MessageID DCTL_STARTING
const isc::log::MessageID DCTL_PROCESS_FAILED
const isc::log::MessageID DCTL_SHUTDOWN_SIGNAL_RECVD
const isc::log::MessageID DCTL_INIT_PROCESS_FAIL
const isc::log::MessageID DCTL_ALREADY_RUNNING
const isc::log::MessageID DCTL_NOT_RUNNING
const isc::log::MessageID DCTL_CONFIG_FILE_LOAD_FAIL
const isc::log::MessageID DCTL_CONFIG_DEPRECATED
const isc::log::MessageID DCTL_UNSUPPORTED_SIGNAL
const isc::log::MessageID DCTL_INIT_PROCESS
bool amRunningAsRoot()
Indicates if current user is root.
Defines the logger used by the top-level component of kea-lfc.