 |
Kea
1.5.0
|
Go to the documentation of this file.
17 #include <kea_version.h>
18 #include <boost/bind.hpp>
31 DControllerBase::DControllerBase(
const char* app_name,
const char* bin_name)
32 : app_name_(app_name), bin_name_(bin_name),
33 verbose_(false), check_only_(false),
44 "Multiple controller instances attempted.");
47 controller_ = controller;
94 }
catch (
const std::exception& ex) {
96 .arg(app_name_).arg(ex.what());
104 .arg(bin_name_).arg(ex.
what());
106 }
catch (
const std::exception& ex) {
108 .arg(app_name_).arg(ex.what());
114 .arg(app_name_).arg(getpid()).arg(VERSION);
118 }
catch (
const std::exception& ex) {
120 .arg(app_name_).arg(ex.what());
122 "Application Process initialization failed: " << ex.
what());
133 .arg(app_name_).arg(comment->stringValue());
135 << comment->stringValue());
144 }
catch (
const std::exception& ex) {
146 .arg(app_name_).arg(ex.what());
148 "Application process event loop failed: " << ex.
what());
153 .arg(app_name_).arg(getpid()).arg(VERSION);
162 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
169 if (config_file.empty()) {
179 std::cerr <<
"Syntax check OK" << std::endl;
184 module_config = whole_config->get(
getAppName());
185 if (!module_config) {
187 " does not include '" <<
getAppName() <<
"' entry");
198 << answer->stringValue());
204 }
catch (
const std::exception& ex) {
225 while ((ch = getopt(argc, argv, opts.c_str())) != -1) {
253 if (optarg == NULL) {
267 <<
static_cast<char>(optopt) <<
"] "
268 << (!optarg ?
"" : optarg));
278 <<
static_cast<char>(ch) <<
"] "
279 << (!optarg ?
"" : optarg));
306 }
catch (
const std::exception& ex) {
334 if (config_file.empty()) {
337 "use -c command line option.");
345 whole_config = Element::fromJSONFile(config_file,
true);
352 ConfigPtr storage = process_->getCfgMgr()->getContext();
359 module_config = whole_config->get(
getAppName());
360 if (!module_config) {
362 " does not include '" <<
372 storage->applyLoggingCfg();
375 }
catch (
const std::exception& ex) {
382 std::string(
"Configuration parsing failed: ") + ex.what());
406 return (process_->configure(new_config,
false));
412 return (process_->configure(new_config,
true));
418 ConstElementPtr config = process_->getCfgMgr()->getContext()->toElement();
426 std::string filename;
429 if (args->getType() != Element::map) {
430 return (
createAnswer(COMMAND_ERROR,
"Argument must be a map"));
433 if (filename_param) {
434 if (filename_param->getType() != Element::string) {
436 "passed parameter 'filename' "
439 filename = filename_param->stringValue();
443 if (filename.empty()) {
447 if (filename.empty()) {
449 "Unable to determine filename."
450 "Please specify filename explicitly."));
457 ElementPtr cfg = process_->getCfgMgr()->getContext()->toElement();
469 if (!cfg->contains(
"Logging")) {
470 ConfigPtr base_cfg = process_->getCfgMgr()->getContext();
475 loginfo = loginfo->get(
"Logging");
479 cfg->set(
"Logging", loginfo);
487 std::string(
"Error during write-config:")
492 "Error writing configuration to " + filename));
497 params->set(
"size", Element::create(
static_cast<long long>(size)));
498 params->set(
"filename", Element::create(filename));
501 + filename +
" successful", params));
506 const int status_code = COMMAND_ERROR;
516 message =
"Missing mandatory 'arguments' parameter.";
518 module_config = args->get(app_name);
519 if (!module_config) {
520 message =
"Missing mandatory '" + app_name +
"' parameter.";
521 }
else if (module_config->getType() != Element::map) {
522 message =
"'" + app_name +
"' parameter expected to be a map.";
526 if (!message.empty()) {
550 arguments->set(
"extended", extended);
572 return (process_->shutdown(args));
578 return (
createAnswer(COMMAND_SUCCESS,
"Process has not been initialized"));
612 IOSignalPtr io_signal = io_signal_queue_->popSignal(sequence_id);
629 .arg(comment->stringValue());
639 DCTL_SHUTDOWN_SIGNAL_RECVD).arg(signum);
655 std::cerr <<
"Usage error: " << text << std::endl;
658 std::cerr <<
"Usage: " << bin_name_ << std::endl
659 <<
" -v: print version number and exit" << std::endl
660 <<
" -V: print extended version information and exit"
662 <<
" -W: display the configuration report and exit"
664 <<
" -d: optional, verbose output " << std::endl
665 <<
" -c <config file name> : mandatory,"
666 <<
" specify name of configuration file" << std::endl
667 <<
" -t <config file name> : check the"
668 <<
" configuration file and exit" << std::endl;
682 std::stringstream tmp;
686 tmp << std::endl << EXTENDED_VERSION << std::endl;
687 tmp <<
"linked with:" << std::endl;
bool isCheckOnly() const
Supplies whether or not check only mode is enabled.
virtual isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr new_config)
Instance method invoked by the configuration event handler and which processes the actual configurati...
void parseArgs(int argc, char *argv[])
Processes the command line arguments.
Exception thrown when the application process encounters an operation in its event loop (i....
virtual size_t writeConfigFile(const std::string &config_file, isc::data::ConstElementPtr cfg=isc::data::ConstElementPtr()) const
Writes current configuration to specified file.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
void checkConfigFile() const
Checks the configuration file name.
static std::string getVersion()
Version.
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 ...
Exception thrown when the controller encounters an operational error.
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
virtual bool customOption(int option, char *optarg)
Virtual method that provides derivations the opportunity to support additional command line options.
std::string getConfigFile() const
Returns config file name.
const char *const * d2_config_report
static void configureLogger(const isc::data::ConstElementPtr &log_config, const isc::process::ConfigPtr &storage)
Configures logger.
virtual std::string getVersionAddendum()
Fetches text containing additional version specifics.
virtual ~DControllerBase()
Destructor.
boost::shared_ptr< IOSignal > IOSignalPtr
Defines a pointer to an IOSignal.
virtual isc::data::ConstElementPtr parseFile(const std::string &file_name)
Parse a given file into Elements.
static void loggerInit(const char *log_name, bool verbose)
Initializes logger.
void createPIDFile(int pid=0)
Creates the PID file.
static void setController(const DControllerBasePtr &controller)
Static setter which sets the singleton instance.
This is a base class for exceptions thrown from the DNS library module.
isc::data::ConstElementPtr configTestHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-test command
Exception thrown when the controller launch fails.
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the SrvConfig.
Exception thrown when the application process fails.
void usage(const std::string &text)
Prints the program usage text to std error.
Defines the logger used by the top-level component of kea-dhcp-ddns.
isc::util::SignalSetPtr signal_set_
A pointer to the object installing custom signal handlers.
uint64_t IOSignalId
Defines a unique identifier type for IOSignal.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
isc::data::ConstElementPtr shutdownHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for 'shutdown' command
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
isc::data::ConstElementPtr versionGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for version-get command
Creates and manages IOSignals.
boost::shared_ptr< DControllerBase > DControllerBasePtr
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...
virtual isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr new_config)
Instance method invoked by the configuration event handler and which processes the actual configurati...
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
virtual isc::data::ConstElementPtr configFromFile()
Reconfigures the process from a configuration file.
virtual const std::string getUsageText() const
Virtual method which can be used to contribute derivation specific usage text.
void setProcName(const std::string &proc_name)
Sets the process name.
virtual const std::string getCustomOpts() const
Virtual method which returns a string containing the option letters for any custom command line optio...
static void setOnReceiptHandler(BoolSignalHandler handler)
Registers a handler as the onreceipt signal handler.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
Exception used to convey version info upwards.
virtual void processSignal(int signum)
Application-level signal processing method.
isc::data::ConstElementPtr configWriteHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-write command
A wrapper interface for the ASIO library.
Exception thrown when a the PID file points to a live PID.
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
isc::log::Logger dctl_logger("dctl")
Defines the logger used within libkea-process library.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
const char *const config_report[]
bool osSignalHandler(int signum)
Handler for processing OS-level signals.
std::string getVersion(bool extended)
returns Kea version on stdout and exit.
void setConfigFile(const std::string &config_file)
Sets the configuration file name.
std::string getConfigReport()
isc::data::ConstElementPtr configGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-get command
static void setDefaultLoggerName(const std::string &logger)
Sets the default logger name.
void initProcess()
Instantiates the application process and then initializes it.
void initSignalHandling()
Initializes signal handling.
boost::shared_ptr< Element > ElementPtr
std::string getAppName() const
Fetches the name of the application under control.
virtual DProcessBase * createProcess()=0
Abstract method that is responsible for instantiating the application process object.
boost::shared_ptr< const Element > ConstElementPtr
Exception thrown when the command line is invalid.
void checkConfigOnly()
Check the configuration.
isc::data::ConstElementPtr shutdownProcess(isc::data::ConstElementPtr args)
Initiates shutdown procedure.
isc::data::ConstElementPtr buildReportHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for 'build-report' command
Represents a collection of signals handled in a customized way.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
void ioSignalHandler(IOSignalId sequence_id)
Handler for processing IOSignals.
void runProcess()
Invokes the application process's event loop,(DBaseProcess::run).
Logging initialization functions.