d_controller.cc 23.1 KB
Newer Older
1
// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
2
//
3 4 5
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6

7
#include <config.h>
8
#include <cc/command_interpreter.h>
9 10
#include <cfgrpt/config_report.h>
#include <exceptions/exceptions.h>
11
#include <log/logger.h>
12
#include <log/logger_support.h>
13
#include <process/daemon.h>
14
#include <process/d_log.h>
15
#include <process/d_controller.h>
16
#include <process/config_base.h>
17

18 19 20 21 22 23
#ifdef HAVE_MYSQL
#include <dhcpsrv/mysql_lease_mgr.h>
#endif
#ifdef HAVE_PGSQL
#include <dhcpsrv/pgsql_lease_mgr.h>
#endif
Tomek Mrugalski's avatar
Tomek Mrugalski committed
24 25
#ifdef HAVE_CQL
#include <dhcpsrv/cql_lease_mgr.h>
26
#endif
27 28
#include <dhcpsrv/memfile_lease_mgr.h>

29
#include <sstream>
30
#include <unistd.h>
31

Francis Dupont's avatar
Francis Dupont committed
32 33 34
using namespace isc::data;
using namespace isc::config;

35
namespace isc {
36
namespace process {
37 38 39 40

DControllerBasePtr DControllerBase::controller_;

// Note that the constructor instantiates the controller's primary IOService.
41
DControllerBase::DControllerBase(const char* app_name, const char* bin_name)
42
    : app_name_(app_name), bin_name_(bin_name),
43
      verbose_(false), check_only_(false),
44
      io_service_(new isc::asiolink::IOService()),
45
      io_signal_queue_() {
46 47
}

48
void
49
DControllerBase::setController(const DControllerBasePtr& controller) {
50 51 52 53 54 55 56
    if (controller_) {
        // This shouldn't happen, but let's make sure it can't be done.
        // It represents a programmatic error.
        isc_throw (DControllerBaseError,
                "Multiple controller instances attempted.");
    }

57
    controller_ = controller;
58 59
}

Francis Dupont's avatar
Francis Dupont committed
60
ConstElementPtr
61
DControllerBase::parseFile(const std::string&) {
Francis Dupont's avatar
Francis Dupont committed
62
    ConstElementPtr elements;
63 64 65
    return (elements);
}

66
void
67
DControllerBase::launch(int argc, char* argv[], const bool test_mode) {
68

69 70 71 72 73
    // Step 1 is to parse the command line arguments.
    try {
        parseArgs(argc, argv);
    } catch (const InvalidUsage& ex) {
        usage(ex.what());
74 75
        // rethrow it with an empty message
        isc_throw(InvalidUsage, "");
76 77
    }

78
    setProcName(bin_name_);
79

80 81
    if (isCheckOnly()) {
        checkConfigOnly();
82
        return;
83
    }
84

85 86 87
    // It is important that we set a default logger name because this name
    // will be used when the user doesn't provide the logging configuration
    // in the Kea configuration file.
88
    Daemon::setDefaultLoggerName(bin_name_);
89 90 91 92

    // Logger's default configuration depends on whether we are in the
    // verbose mode or not. CfgMgr manages the logger configuration so
    // the verbose mode is set for CfgMgr.
93
    Daemon::setVerbose(verbose_);
94

95 96 97 98
    // Do not initialize logger here if we are running unit tests. It would
    // replace an instance of unit test specific logger.
    if (!test_mode) {
        // Now that we know what the mode flags are, we can init logging.
99
        Daemon::loggerInit(bin_name_.c_str(), verbose_);
100
    }
101

102 103
    try {
        createPIDFile();
104
    } catch (const DaemonPIDExists& ex) {
105
        LOG_FATAL(dctl_logger, DCTL_ALREADY_RUNNING)
106 107 108
                  .arg(bin_name_).arg(ex.what());
        isc_throw (LaunchError, "Launch Failed: " << ex.what());
    } catch (const std::exception& ex) {
109
        LOG_FATAL(dctl_logger, DCTL_PID_FILE_ERROR)
110 111 112 113
                  .arg(app_name_).arg(ex.what());
        isc_throw (LaunchError, "Launch failed: " << ex.what());
    }

114 115 116
    // Log the starting of the service.
    LOG_INFO(dctl_logger, DCTL_STARTING)
        .arg(app_name_).arg(getpid()).arg(VERSION);
117
    try {
118
        // Step 2 is to create and initialize the application process object.
119
        initProcess();
120
    } catch (const std::exception& ex) {
121 122 123
        LOG_FATAL(dctl_logger, DCTL_INIT_PROCESS_FAIL)
                  .arg(app_name_).arg(ex.what());
        isc_throw (ProcessInitError,
124
                   "Application Process initialization failed: " << ex.what());
125
    }
126

Francis Dupont's avatar
Francis Dupont committed
127 128
    LOG_DEBUG(dctl_logger, isc::log::DBGLVL_START_SHUT, DCTL_STANDALONE)
        .arg(app_name_);
129 130 131

    // Step 3 is to load configuration from file.
    int rcode;
Francis Dupont's avatar
Francis Dupont committed
132
    ConstElementPtr comment = parseAnswer(rcode, configFromFile());
133 134 135
    if (rcode != 0) {
        LOG_FATAL(dctl_logger, DCTL_CONFIG_FILE_LOAD_FAIL)
                  .arg(app_name_).arg(comment->stringValue());
Vincent Legout's avatar
Vincent Legout committed
136
        isc_throw (ProcessInitError, "Could Not load configuration file: "
137
                   << comment->stringValue());
138
    }
139

140 141 142
    // Everything is clear for launch, so start the application's
    // event loop.
    try {
143 144
        // Now that we have a proces, we can set up signal handling.
        initSignalHandling();
145 146
        runProcess();
    } catch (const std::exception& ex) {
147 148 149
        LOG_FATAL(dctl_logger, DCTL_PROCESS_FAILED)
                  .arg(app_name_).arg(ex.what());
        isc_throw (ProcessRunError,
150
                   "Application process event loop failed: " << ex.what());
151 152
    }

153 154 155
    // All done, so bail out.
    LOG_INFO(dctl_logger, DCTL_SHUTDOWN)
        .arg(app_name_).arg(getpid()).arg(VERSION);
156 157
}

158 159 160 161 162 163 164
void
DControllerBase::checkConfigOnly() {
    try {
        // We need to initialize logging, in case any error
        // messages are to be printed.
        // This is just a test, so we don't care about lockfile.
        setenv("KEA_LOCKFILE_DIR", "none", 0);
165 166
        Daemon::setDefaultLoggerName(bin_name_);
        Daemon::setVerbose(verbose_);
167 168 169 170 171 172 173 174
        Daemon::loggerInit(bin_name_.c_str(), verbose_);

        // Check the syntax first.
        std::string config_file = getConfigFile();
        if (config_file.empty()) {
            // Basic sanity check: file name must not be empty.
            isc_throw(InvalidUsage, "JSON configuration file not specified");
        }
Francis Dupont's avatar
Francis Dupont committed
175
        ConstElementPtr whole_config = parseFile(config_file);
176 177 178 179 180 181 182 183 184
        if (!whole_config) {
            // No fallback to fromJSONFile
            isc_throw(InvalidUsage, "No configuration found");
        }
        if (verbose_) {
            std::cerr << "Syntax check OK" << std::endl;
        }

        // Check the logic next.
Francis Dupont's avatar
Francis Dupont committed
185
        ConstElementPtr module_config;
186 187 188 189 190 191 192 193 194
        module_config = whole_config->get(getAppName());
        if (!module_config) {
            isc_throw(InvalidUsage, "Config file " << config_file <<
                      " does not include '" << getAppName() << "' entry");
        }

        // Get an application process object.
        initProcess();

Francis Dupont's avatar
Francis Dupont committed
195
        ConstElementPtr answer = checkConfig(module_config);
196
        int rcode = 0;
Francis Dupont's avatar
Francis Dupont committed
197
        answer = parseAnswer(rcode, answer);
198 199 200 201 202 203 204 205 206 207 208 209 210 211
        if (rcode != 0) {
            isc_throw(InvalidUsage, "Error encountered: "
                      << answer->stringValue());
        }
    } catch (const VersionMessage&) {
        throw;
    } catch (const InvalidUsage&) {
        throw;
    } catch (const std::exception& ex) {
        isc_throw(InvalidUsage, "Syntax check failed with: " << ex.what());
    }
    return;
}

212 213 214
void
DControllerBase::parseArgs(int argc, char* argv[])
{
215
    // Iterate over the given command line options. If its a stock option
216
    // ("c" or "d") handle it here.  If its a valid custom option, then
217 218
    // invoke customOption.
    int ch;
219
    opterr = 0;
220
    optind = 1;
221
    std::string opts("dvVWc:t:" + getCustomOpts());
222 223
    while ((ch = getopt(argc, argv, opts.c_str())) != -1) {
        switch (ch) {
224
        case 'd':
225 226 227 228
            // Enables verbose logging.
            verbose_ = true;
            break;

229
        case 'v':
230 231 232 233
            // gather Kea version and throw so main() can catch and return
            // rather than calling exit() here which disrupts gtest.
            isc_throw(VersionMessage, getVersion(false));
            break;
234 235

        case 'V':
236 237 238 239
            // gather Kea version and throw so main() can catch and return
            // rather than calling exit() here which disrupts gtest.
            isc_throw(VersionMessage, getVersion(true));
            break;
240

241 242 243 244 245 246
        case 'W':
            // gather Kea config report and throw so main() can catch and
            // return rather than calling exit() here which disrupts gtest.
            isc_throw(VersionMessage, isc::detail::getConfigReport());
            break;

247
        case 'c':
248
        case 't':
249 250 251 252 253
            // config file name
            if (optarg == NULL) {
                isc_throw(InvalidUsage, "configuration file name missing");
            }

254
            setConfigFile(optarg);
255 256 257 258

            if (ch == 't') {
                check_only_ = true;
            }
259 260 261 262
            break;

        case '?': {
            // We hit an invalid option.
263
            isc_throw(InvalidUsage, "unsupported option: ["
264 265
                      << static_cast<char>(optopt) << "] "
                      << (!optarg ? "" : optarg));
266 267 268

            break;
            }
269

270 271 272
        default:
            // We hit a valid custom option
            if (!customOption(ch, optarg)) {
273
                // This would be a programmatic error.
274
                isc_throw(InvalidUsage, " Option listed but implemented?: ["
275 276
                          << static_cast<char>(ch) << "] "
                          << (!optarg ? "" : optarg));
277 278 279 280 281 282 283
            }
            break;
        }
    }

    // There was too much information on the command line.
    if (argc > optind) {
284
        isc_throw(InvalidUsage, "extraneous command line information");
285 286 287
    }
}

288
bool
289 290 291 292 293 294 295 296
DControllerBase::customOption(int /* option */, char* /*optarg*/)
{
    // Default implementation returns false.
    return (false);
}

void
DControllerBase::initProcess() {
Francis Dupont's avatar
Francis Dupont committed
297 298
    LOG_DEBUG(dctl_logger, isc::log::DBGLVL_START_SHUT, DCTL_INIT_PROCESS)
        .arg(app_name_);
299 300

    // Invoke virtual method to instantiate the application process.
301
    try {
302
        process_.reset(createProcess());
303
    } catch (const std::exception& ex) {
304
        isc_throw(DControllerBaseError, std::string("createProcess failed: ")
305
                  + ex.what());
306 307 308 309
    }

    // This is pretty unlikely, but will test for it just to be safe..
    if (!process_) {
310
        isc_throw(DControllerBaseError, "createProcess returned NULL");
311
    }
312

313 314
    // Invoke application's init method (Note this call should throw
    // DProcessBaseError if it fails).
315 316 317
    process_->init();
}

Francis Dupont's avatar
Francis Dupont committed
318
ConstElementPtr
319
DControllerBase::configFromFile() {
320 321
    // Rollback any previous staging configuration. For D2, only a
    // logger configuration is used here.
322 323 324
    // We're not using cfgmgr to store logging configuration anymore.
    // isc::dhcp::CfgMgr::instance().rollback();

325
    // Will hold configuration.
Francis Dupont's avatar
Francis Dupont committed
326
    ConstElementPtr module_config;
327
    // Will receive configuration result.
Francis Dupont's avatar
Francis Dupont committed
328
    ConstElementPtr answer;
329
    try {
330
        std::string config_file = getConfigFile();
331 332 333 334 335 336
        if (config_file.empty()) {
            // Basic sanity check: file name must not be empty.
            isc_throw(BadValue, "JSON configuration file not specified. Please "
                                "use -c command line option.");
        }

337 338
        // If parseFile returns an empty pointer, then pass the file onto the
        // original JSON parser.
Francis Dupont's avatar
Francis Dupont committed
339
        ConstElementPtr whole_config = parseFile(config_file);
340 341
        if (!whole_config) {
            // Read contents of the file and parse it as JSON
Francis Dupont's avatar
Francis Dupont committed
342
            whole_config = Element::fromJSONFile(config_file, true);
343
        }
344

345 346 347 348
        // Let's configure logging before applying the configuration,
        // so we can log things during configuration process.

        // Temporary storage for logging configuration
349
        ConfigPtr storage = process_->getCfgMgr()->getContext();
350

Tomek Mrugalski's avatar
Tomek Mrugalski committed
351 352
        // Get 'Logging' element from the config and use it to set up
        // logging. If there's no such element, we'll just pass NULL.
353
        Daemon::configureLogger(whole_config->get("Logging"), storage);
354

355 356 357 358 359 360 361
        // Extract derivation-specific portion of the configuration.
        module_config = whole_config->get(getAppName());
        if (!module_config) {
            isc_throw(BadValue, "Config file " << config_file <<
                                " does not include '" <<
                                 getAppName() << "' entry.");
        }
362

363
        answer = updateConfig(module_config);
364
        int rcode = 0;
Francis Dupont's avatar
Francis Dupont committed
365
        parseAnswer(rcode, answer);
366 367 368
        if (!rcode) {
            // Configuration successful, so apply the logging configuration
            // to log4cplus.
369
            storage->applyLoggingCfg();
370 371
        }

372
    } catch (const std::exception& ex) {
373
        // Rollback logging configuration.
374 375 376
        // We don't use CfgMgr to store logging information anymore.
        // isc::dhcp::CfgMgr::instance().rollback();

377
        // build an error result
Francis Dupont's avatar
Francis Dupont committed
378 379
        ConstElementPtr error = createAnswer(COMMAND_ERROR,
                 std::string("Configuration parsing failed: ") + ex.what());
380
        return (error);
381 382
    }

383
    return (answer);
384 385 386 387
}

void
DControllerBase::runProcess() {
Francis Dupont's avatar
Francis Dupont committed
388 389
    LOG_DEBUG(dctl_logger, isc::log::DBGLVL_START_SHUT, DCTL_RUN_PROCESS)
        .arg(app_name_);
390 391 392 393 394
    if (!process_) {
        // This should not be possible.
        isc_throw(DControllerBaseError, "Process not initialized");
    }

395 396
    // Invoke the application process's run method. This may throw
    // DProcessBaseError
397 398 399
    process_->run();
}

400
// Instance method for handling new config
Francis Dupont's avatar
Francis Dupont committed
401 402
ConstElementPtr
DControllerBase::updateConfig(ConstElementPtr new_config) {
403 404 405 406
    return (process_->configure(new_config, false));
}

// Instance method for checking new config
Francis Dupont's avatar
Francis Dupont committed
407 408
ConstElementPtr
DControllerBase::checkConfig(ConstElementPtr new_config) {
409
    return (process_->configure(new_config, true));
410 411
}

Francis Dupont's avatar
Francis Dupont committed
412
ConstElementPtr
Francis Dupont's avatar
Francis Dupont committed
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
DControllerBase::configGetHandler(const std::string&,
                                  ConstElementPtr /*args*/) {
    ConstElementPtr config = process_->getCfgMgr()->getContext()->toElement();

    return (createAnswer(COMMAND_SUCCESS, config));
}

ConstElementPtr
DControllerBase::configWriteHandler(const std::string&,
                                    ConstElementPtr args) {
    std::string filename;

    if (args) {
        if (args->getType() != Element::map) {
            return (createAnswer(COMMAND_ERROR, "Argument must be a map"));
        }
        ConstElementPtr filename_param = args->get("filename");
        if (filename_param) {
            if (filename_param->getType() != Element::string) {
                return (createAnswer(COMMAND_ERROR,
                                     "passed parameter 'filename' "
                                     "is not a string"));
            }
            filename = filename_param->stringValue();
        }
    }

    if (filename.empty()) {
        // filename parameter was not specified, so let's use
        // whatever we remember
        filename = getConfigFile();
        if (filename.empty()) {
            return (createAnswer(COMMAND_ERROR,
                                 "Unable to determine filename."
                                 "Please specify filename explicitly."));
        }
    }

451

Francis Dupont's avatar
Francis Dupont committed
452 453
    // Ok, it's time to write the file.
    size_t size = 0;
454 455 456 457 458 459 460 461 462 463 464 465
    ElementPtr cfg = process_->getCfgMgr()->getContext()->toElement();

    // Logging storage is messed up in CA. During its configuration (see
    // DControllerBase::configFromFile() it calls Daemon::configureLogger()
    // that stores the logging info in isc::dhcp::CfgMgr::getStagingCfg().
    // This is later moved to getCurrentCfg() when the configuration is
    // commited. All control-agent specific configuration is stored in
    // a structure accessible by process_->getCfgMgr()->getContext(). Note
    // logging information is not stored there.
    //
    // As a result, we need to extract the CA configuration from one
    // place and logging from another.
466 467 468 469 470 471 472 473 474 475 476 477
    if (!cfg->contains("Logging")) {
        ConfigPtr base_cfg = process_->getCfgMgr()->getContext();

        ConstElementPtr loginfo = base_cfg->toElement();
        if (loginfo) {
            // If there was a config stored in dhcp::CfgMgr, try to get Logging info from it.
            loginfo = loginfo->get("Logging");
        }
        if (loginfo) {
            // If there is some logging information, add it to our config.
            cfg->set("Logging", loginfo);
        }
478 479
    }

Francis Dupont's avatar
Francis Dupont committed
480
    try {
481
        size = writeConfigFile(filename, cfg);
Francis Dupont's avatar
Francis Dupont committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
    } catch (const isc::Exception& ex) {
        return (createAnswer(COMMAND_ERROR,
                             std::string("Error during write-config:")
                             + ex.what()));
    }
    if (size == 0) {
        return (createAnswer(COMMAND_ERROR,
                             "Error writing configuration to " + filename));
    }

    // Ok, it's time to return the successful response.
    ElementPtr params = Element::createMap();
    params->set("size", Element::create(static_cast<long long>(size)));
    params->set("filename", Element::create(filename));

    return (createAnswer(CONTROL_RESULT_SUCCESS, "Configuration written to "
                         + filename + " successful", params));
}

ConstElementPtr
DControllerBase::configTestHandler(const std::string&, ConstElementPtr args) {
503 504
    const int status_code = COMMAND_ERROR; // 1 indicates an error
    ConstElementPtr module_config;
505
    std::string app_name = getAppName();
Francis Dupont's avatar
Francis Dupont committed
506 507 508
    std::string message;

    // Command arguments are expected to be:
509 510
    // { "Module": { ... }, "Logging": { ... } }
    // The Logging component is technically optional. If it's not supplied
Francis Dupont's avatar
Francis Dupont committed
511 512 513 514
    // logging will revert to default logging.
    if (!args) {
        message = "Missing mandatory 'arguments' parameter.";
    } else {
515
      module_config = args->get(app_name);
516
        if (!module_config) {
517
            message = "Missing mandatory '" + app_name + "' parameter.";
518
        } else if (module_config->getType() != Element::map) {
519
            message = "'" + app_name + "' parameter expected to be a map.";
Francis Dupont's avatar
Francis Dupont committed
520 521 522 523 524 525 526 527 528 529 530 531 532
        }
    }

    if (!message.empty()) {
        // Something is amiss with arguments, return a failure response.
        ConstElementPtr result = isc::config::createAnswer(status_code,
                                                           message);
        return (result);
    }

    // We are starting the configuration process so we should remove any
    // staging configuration that has been created during previous
    // configuration attempts.
533 534
    // We're not using cfgmgr to store logging information anymore.
    // isc::dhcp::CfgMgr::instance().rollback();
Francis Dupont's avatar
Francis Dupont committed
535 536

    // Now we check the server proper.
537
    return (checkConfig(module_config));
Francis Dupont's avatar
Francis Dupont committed
538 539
}

Francis Dupont's avatar
Francis Dupont committed
540
ConstElementPtr
Francis Dupont's avatar
Francis Dupont committed
541
DControllerBase::versionGetHandler(const std::string&, ConstElementPtr) {
Francis Dupont's avatar
Francis Dupont committed
542
    ConstElementPtr answer;
543

Francis Dupont's avatar
Francis Dupont committed
544 545 546 547 548
    // For version-get put the extended version in arguments
    ElementPtr extended = Element::create(getVersion(true));
    ElementPtr arguments = Element::createMap();
    arguments->set("extended", extended);
    answer = createAnswer(COMMAND_SUCCESS, getVersion(false), arguments);
549 550 551
    return (answer);
}

Francis Dupont's avatar
Francis Dupont committed
552
ConstElementPtr
553
DControllerBase::buildReportHandler(const std::string&, ConstElementPtr) {
Francis Dupont's avatar
Francis Dupont committed
554 555
    return (createAnswer(COMMAND_SUCCESS, isc::detail::getConfigReport()));
}
556

Francis Dupont's avatar
Francis Dupont committed
557 558 559 560 561 562 563
ConstElementPtr
DControllerBase::shutdownHandler(const std::string&, ConstElementPtr args) {
    // Shutdown is universal.  If its not that, then try it as
    // a custom command supported by the derivation.  If that
    // doesn't pan out either, than send to it the application
    // as it may be supported there.
    return (shutdownProcess(args));
564 565
}

Francis Dupont's avatar
Francis Dupont committed
566 567
ConstElementPtr
DControllerBase::shutdownProcess(ConstElementPtr args) {
568
    if (process_) {
569
        return (process_->shutdown(args));
570
    }
571

572 573 574
    // Not really a failure, but this condition is worth noting. In reality
    // it should be pretty hard to cause this.
    LOG_WARN(dctl_logger, DCTL_NOT_RUNNING).arg(app_name_);
Francis Dupont's avatar
Francis Dupont committed
575
    return (createAnswer(COMMAND_SUCCESS, "Process has not been initialized"));
576 577
}

578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
void
DControllerBase::initSignalHandling() {
    /// @todo block everything we don't handle

    // Create our signal queue.
    io_signal_queue_.reset(new IOSignalQueue(io_service_));

    // Install the on-receipt handler
    util::SignalSet::setOnReceiptHandler(boost::bind(&DControllerBase::
                                                     osSignalHandler,
                                                     this, _1));
    // Register for the signals we wish to handle.
    signal_set_.reset(new util::SignalSet(SIGHUP,SIGINT,SIGTERM));
}

bool
DControllerBase::osSignalHandler(int signum) {
    // Create a IOSignal to propagate the signal to IOService.
    io_signal_queue_->pushSignal(signum, boost::bind(&DControllerBase::
                                                     ioSignalHandler,
                                                     this, _1));
    return (true);
}

void
DControllerBase::ioSignalHandler(IOSignalId sequence_id) {
    // Pop the signal instance off the queue.  This should make us
    // the only one holding it, so when we leave it should be freed.
    // (note that popSignal will throw if signal is not found, which
    // in turn will caught, logged, and swallowed by IOSignal callback
    // invocation code.)
    IOSignalPtr io_signal = io_signal_queue_->popSignal(sequence_id);

    // Now call virtual signal processing method.
    processSignal(io_signal->getSignum());
}

void
DControllerBase::processSignal(int signum) {
    switch (signum) {
        case SIGHUP:
        {
620
            LOG_INFO(dctl_logger, DCTL_CFG_FILE_RELOAD_SIGNAL_RECVD)
621 622
                     .arg(signum).arg(getConfigFile());
            int rcode;
Francis Dupont's avatar
Francis Dupont committed
623
            ConstElementPtr comment = parseAnswer(rcode, configFromFile());
624
            if (rcode != 0) {
625
                LOG_ERROR(dctl_logger, DCTL_CFG_FILE_RELOAD_ERROR)
626 627 628 629 630 631 632 633 634
                          .arg(comment->stringValue());
            }

            break;
        }

        case SIGINT:
        case SIGTERM:
        {
Francis Dupont's avatar
Francis Dupont committed
635
            LOG_DEBUG(dctl_logger, isc::log::DBGLVL_START_SHUT,
636
                      DCTL_SHUTDOWN_SIGNAL_RECVD).arg(signum);
Francis Dupont's avatar
Francis Dupont committed
637 638
            ElementPtr arg_set;
            shutdownHandler(SHUT_DOWN_COMMAND, arg_set);
639 640 641 642
            break;
        }

        default:
643
            LOG_WARN(dctl_logger, DCTL_UNSUPPORTED_SIGNAL).arg(signum);
644 645 646 647
            break;
    }
}

648 649 650 651
void
DControllerBase::usage(const std::string & text)
{
    if (text != "") {
652
        std::cerr << "Usage error: " << text << std::endl;
653 654
    }

655
    std::cerr << "Usage: " << bin_name_ <<  std::endl
656 657
              << "  -v: print version number and exit" << std::endl
              << "  -V: print extended version information and exit"
658 659
              << std::endl
              << "  -W: display the configuration report and exit"
660 661 662
              << std::endl
              << "  -d: optional, verbose output " << std::endl
              << "  -c <config file name> : mandatory,"
663 664 665
              << " specify name of configuration file" << std::endl
              << "  -t <config file name> : check the"
              << " configuration file and exit" << std::endl;
666

667
    // add any derivation specific usage
668
    std::cerr << getUsageText() << std::endl;
669 670 671 672 673
}

DControllerBase::~DControllerBase() {
}

674 675 676
// Refer to config_report so it will be embedded in the binary
const char* const* d2_config_report = isc::detail::config_report;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
677
std::string
678
DControllerBase::getVersion(bool extended) {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
679 680 681 682
    std::stringstream tmp;

    tmp << VERSION;
    if (extended) {
683
        tmp << std::endl << EXTENDED_VERSION << std::endl;
684 685
        tmp << "linked with:" << std::endl;
        tmp << isc::log::Logger::getVersion() << std::endl;
686
        tmp << getVersionAddendum();
Tomek Mrugalski's avatar
Tomek Mrugalski committed
687 688 689 690
    }

    return (tmp.str());
}
691

692
}; // namespace isc::process
693 694

}; // namespace isc