From: Thomas Markwalder Date: Thu, 2 Jul 2015 21:17:08 +0000 (-0400) Subject: [3769] DHCPv6 now uses PID file X-Git-Tag: trac3785_base~2^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5776ee0cc7f7614c83c5395f5c97f443f9c39ce5;p=thirdparty%2Fkea.git [3769] DHCPv6 now uses PID file Added PID file creation to DHCP6 src/bin/dhcp6/dhcp6_messages.mes - added log DHCP6_ALREADY_RUNNING src/bin/dhcp6/main.cc - added logic to create the PID and catch exception specific to PID conflict src/bin/dhcp6/tests/Makefile.am - exports KEA_PIDFILE_DIR src/bin/dhcp6/tests/dhcp6_process_tests.sh.in - added call to server_pid_file_test src/bin/dhcp6/tests/dhcp6_unittests.cc - main(int argc, char* argv[]) sets env var KEA_PIDFILE_DIR --- diff --git a/src/bin/d2/d_controller.cc b/src/bin/d2/d_controller.cc index 6bbc304453..8aa18c77f9 100644 --- a/src/bin/d2/d_controller.cc +++ b/src/bin/d2/d_controller.cc @@ -70,7 +70,7 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) { throw; // rethrow it } - Daemon::setProcName(bin_name_); + setProcName(bin_name_); // 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 @@ -187,7 +187,7 @@ DControllerBase::parseArgs(int argc, char* argv[]) isc_throw(InvalidUsage, "configuration file name missing"); } - Daemon::setConfigFile(optarg); + setConfigFile(optarg); break; case '?': { diff --git a/src/bin/dhcp4/main.cc b/src/bin/dhcp4/main.cc index ca49d30eee..f428c3f3f8 100644 --- a/src/bin/dhcp4/main.cc +++ b/src/bin/dhcp4/main.cc @@ -145,8 +145,9 @@ main(int argc, char* argv[]) { // Remember verbose-mode server.setVerbose(verbose_mode); - Daemon::setProcName(DHCP4_NAME); - Daemon::setConfigFile(config_file); + // Create our PID file. + server.setProcName(DHCP4_NAME); + server.setConfigFile(config_file); server.createPIDFile(); try { diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index 6643da3f3b..b82e6475e9 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -19,6 +19,16 @@ This message is printed when DHCPv6 server enabled an interface to be used to receive DHCPv6 traffic. IPv6 socket on this interface will be opened once Interface Manager starts up procedure of opening sockets. +% DHCP6_ALREADY_RUNNING %1 already running? %2 +This is an error message that occurs when the DHCPv6 server encounters +a pre-existing PID file which contains the PID of a running process. +This most likely indicates an attempt to start a second instance of +the server using the same configuration file. It is possible, though +unlikely that the PID file is a remnant left behind by a server crash or +power failure and the PID it contains refers to a process other than +the server. In such an event, it would be necessary to manually remove +the PID file. + % DHCP6_ADD_GLOBAL_STATUS_CODE %1: adding Status Code to DHCPv6 packet: %2 This message is logged when the server is adding the top-level Status Code option. The first argument includes the client and the diff --git a/src/bin/dhcp6/kea_controller.cc b/src/bin/dhcp6/kea_controller.cc index 18d416dc5c..f1fc901f97 100644 --- a/src/bin/dhcp6/kea_controller.cc +++ b/src/bin/dhcp6/kea_controller.cc @@ -174,9 +174,6 @@ namespace dhcp { void ControlledDhcpv6Srv::init(const std::string& file_name) { - // Call parent class's init to initialize file name. - Daemon::init(file_name); - // Configure the server using JSON file. configure(file_name); diff --git a/src/bin/dhcp6/main.cc b/src/bin/dhcp6/main.cc index d780d395c2..6e1fb5c707 100644 --- a/src/bin/dhcp6/main.cc +++ b/src/bin/dhcp6/main.cc @@ -148,6 +148,11 @@ main(int argc, char* argv[]) { // Remember verbose-mode server.setVerbose(verbose_mode); + // Create our PID file + server.setProcName(DHCP6_NAME); + server.setConfigFile(config_file); + server.createPIDFile(); + try { // Initialize the server, e.g. establish control session // Read a configuration file @@ -177,6 +182,17 @@ main(int argc, char* argv[]) { LOG_INFO(dhcp6_logger, DHCP6_SHUTDOWN); + } catch (const isc::dhcp::DaemonPIDExists& ex) { + // First, we print the error on stderr (that should always work) + cerr << DHCP6_NAME << " already running? " << ex.what() + << endl; + + // Let's also try to log it using logging system, but we're not + // sure if it's usable (the exception may have been thrown from + // the logger subsystem) + LOG_FATAL(dhcp6_logger, DHCP6_ALREADY_RUNNING) + .arg(DHCP6_NAME).arg(ex.what()); + ret = EXIT_FAILURE; } catch (const std::exception& ex) { // First, we print the error on stderr (that should always work) diff --git a/src/bin/dhcp6/tests/Makefile.am b/src/bin/dhcp6/tests/Makefile.am index b4157c72e1..2d444bc2c1 100644 --- a/src/bin/dhcp6/tests/Makefile.am +++ b/src/bin/dhcp6/tests/Makefile.am @@ -12,6 +12,7 @@ check-local: for shtest in $(SHTESTS) ; do \ echo Running test: $$shtest ; \ export KEA_LOCKFILE_DIR=$(abs_top_builddir); \ + export KEA_PIDFILE_DIR=$(abs_top_builddir); \ ${SHELL} $(abs_builddir)/$$shtest || exit ; \ done diff --git a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in index fd3e6065db..e9748b8419 100755 --- a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in +++ b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in @@ -273,6 +273,7 @@ returned %d." test_finish 0 } +server_pid_file_test "${CONFIG}" DHCP6_ALREADY_RUNNING dynamic_reconfiguration_test shutdown_test "dhcpv6.sigterm_test" 15 shutdown_test "dhcpv6.sigint_test" 2 diff --git a/src/bin/dhcp6/tests/dhcp6_unittests.cc b/src/bin/dhcp6/tests/dhcp6_unittests.cc index d9695e9d6b..0c15300d6f 100644 --- a/src/bin/dhcp6/tests/dhcp6_unittests.cc +++ b/src/bin/dhcp6/tests/dhcp6_unittests.cc @@ -22,6 +22,7 @@ main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); isc::log::initLogger(); + setenv("KEA_PIDFILE_DIR", TEST_DATA_BUILDDIR, 1); int result = RUN_ALL_TESTS(); return result;