Parcourir la source

[3406] Implemented support for SIGTERM and SIGINT signals handling.

Marcin Siodelski il y a 11 ans
Parent
commit
422838fb06
2 fichiers modifiés avec 14 ajouts et 5 suppressions
  1. 13 4
      src/bin/dhcp6/kea_controller.cc
  2. 1 1
      src/bin/dhcp6/tests/dhcp6_test_func.sh

+ 13 - 4
src/bin/dhcp6/kea_controller.cc

@@ -128,8 +128,11 @@ void configure(const std::string& file_name) {
 
 
 /// @brief Signals handler for DHCPv6 server.
 /// @brief Signals handler for DHCPv6 server.
 ///
 ///
-/// Currently, this function handles SIGHUP signal only. When this signal
-/// is received it triggeres DHCSP server reconfiguration.
+/// This signal handler handles the following signals received by the DHCPv6
+/// server process:
+/// - SIGHUP - triggers server's dynamic reconfiguration.
+/// - SIGTERM - triggers server's shut down.
+/// - SIGINT - triggers server's shut down.
 ///
 ///
 /// @param signo Signal number received.
 /// @param signo Signal number received.
 void signalHandler(int signo) {
 void signalHandler(int signo) {
@@ -144,6 +147,9 @@ void signalHandler(int signo) {
             // the server keeps working.
             // the server keeps working.
             LOG_ERROR(dhcp6_logger, DHCP6_DYNAMIC_RECONFIGURATION_FAIL);
             LOG_ERROR(dhcp6_logger, DHCP6_DYNAMIC_RECONFIGURATION_FAIL);
         }
         }
+    } else if ((signo == SIGTERM) || (signo == SIGINT)) {
+        ElementPtr params(new isc::data::MapElement());
+        ControlledDhcpv6Srv::processCommand("shutdown", params);
     }
     }
 }
 }
 
 
@@ -164,9 +170,12 @@ ControlledDhcpv6Srv::init(const std::string& file_name) {
     // methods are called in processConfig() which is called by
     // methods are called in processConfig() which is called by
     // processCommand("reload-config", ...)
     // processCommand("reload-config", ...)
 
 
-    // Set signal handler function for SIGHUP. When the SIGHUP is received
-    // by the process the server reconfiguration will be triggered.
+    // Set signal handlers. When the SIGHUP is received by the process
+    // the server reconfiguration will be triggered. When SIGTERM or
+    // SIGINT will be received, the server will start shutting down.
     signal(SIGHUP, signalHandler);
     signal(SIGHUP, signalHandler);
+    signal(SIGTERM, signalHandler);
+    signal(SIGINT, signalHandler);
 }
 }
 
 
 void ControlledDhcpv6Srv::cleanup() {
 void ControlledDhcpv6Srv::cleanup() {

+ 1 - 1
src/bin/dhcp6/tests/dhcp6_test_func.sh

@@ -153,6 +153,7 @@ wait_for_message() {
     _WAIT_FOR_MESSAGE=0
     _WAIT_FOR_MESSAGE=0
     # Check if log file exists and if we reached timeout.
     # Check if log file exists and if we reached timeout.
     while [ ! -s {LOG_FILE} ] && [ ${loops} -le ${timeout} ]; do
     while [ ! -s {LOG_FILE} ] && [ ${loops} -le ${timeout} ]; do
+        printf "."
         # Check if the message has been logged.
         # Check if the message has been logged.
         get_log_messages ${message}
         get_log_messages ${message}
         if [ ${_GET_LOG_MESSAGES} -eq ${occurrences} ]; then
         if [ ${_GET_LOG_MESSAGES} -eq ${occurrences} ]; then
@@ -161,7 +162,6 @@ wait_for_message() {
             return
             return
         fi
         fi
         # Message not recorded. Keep going.
         # Message not recorded. Keep going.
-        printf "."
         sleep 1
         sleep 1
         loops=`expr ${loops} + 1`
         loops=`expr ${loops} + 1`
     done
     done