]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3769] DHCPv6 now uses PID file
authorThomas Markwalder <tmark@isc.org>
Thu, 2 Jul 2015 21:17:08 +0000 (17:17 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 2 Jul 2015 21:17:08 +0000 (17:17 -0400)
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

src/bin/d2/d_controller.cc
src/bin/dhcp4/main.cc
src/bin/dhcp6/dhcp6_messages.mes
src/bin/dhcp6/kea_controller.cc
src/bin/dhcp6/main.cc
src/bin/dhcp6/tests/Makefile.am
src/bin/dhcp6/tests/dhcp6_process_tests.sh.in
src/bin/dhcp6/tests/dhcp6_unittests.cc

index 6bbc304453eb401e709279d818efff2becc32377..8aa18c77f9a76b735f8ecfa7a6ac1a1a93c4ab81 100644 (file)
@@ -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 '?': {
index ca49d30eee1aa3af3253dfd9cb6161d7035e8351..f428c3f3f857ab87438b2eefbfb287e00f8fef61 100644 (file)
@@ -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 {
index 6643da3f3b56ba6e43ebd20a4322fe9d579e54ac..b82e6475e9ac7e6af23dd831170340e6c73b7084 100644 (file)
@@ -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
index 18d416dc5ca330f05fd08d8f2b7f8e41d23ffa76..f1fc901f97800a1e60c6977af7b1c2846352c5a7 100644 (file)
@@ -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);
 
index d780d395c277152032f7790f65595a086c73d161..6e1fb5c70715611d1e9f2a89b42a7fb0df465033 100644 (file)
@@ -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)
index b4157c72e11d7e69f87537f9a16cdd86b8addf37..2d444bc2c1eb48ebd2740fc070e7965cbfe838db 100644 (file)
@@ -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
 
index fd3e6065db9012e55812d00ec90639a76ce80d9e..e9748b84196383c7cfe68c64075bfd34ee3c105b 100755 (executable)
@@ -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
index d9695e9d6baf2262d2568d2dd4ec05c72f5fba5f..0c15300d6f5e1c010be0e5f48bb696ba24672d01 100644 (file)
@@ -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;