Browse Source

[5338] keactrl uses different config file locations for different daemons.

Marcin Siodelski 7 years ago
parent
commit
e5f81a131f

+ 5 - 2
src/bin/keactrl/keactrl.conf.in

@@ -5,8 +5,11 @@
 # prefix holds the location where the Kea is installed.
 prefix=@prefix@
 
-# Location of Kea configuration file.
-kea_config_file=@sysconfdir@/@PACKAGE@/kea.conf
+# Location of Kea configuration files.
+kea_dhcp4_config_file=@sysconfdir@/@PACKAGE@/kea.conf
+kea_dhcp6_config_file=@sysconfdir@/@PACKAGE@/kea.conf
+kea_dhcp_ddns_config_file=@sysconfdir@/@PACKAGE@/kea.conf
+kea_ctrl_agent_config_file=@sysconfdir@/@PACKAGE@/kea.conf
 
 # Location of Kea binaries.
 exec_prefix=@exec_prefix@

+ 53 - 33
src/bin/keactrl/keactrl.in

@@ -65,6 +65,22 @@ usage() {
 get_pid_from_file() {
     local proc_name=${1} # Process name.
 
+    local kea_config_file=
+    case ${proc_name} in
+    kea-dhcp4)
+        kea_config_file=${kea_dhcp4_config_file}
+        ;;
+    kea-dhcp6)
+        kea_config_file=${kea_dhcp6_config_file}
+        ;;
+    kea-dhcp-ddns)
+        kea_config_file=${kea_dhcp_ddns_config_file}
+        ;;
+    kea-ctrl-agent)
+        kea_config_file=${kea_ctrl_agent_config_file}
+        ;;
+    esac
+
     # Extract the name portion of the config file
     local conf_name=$(basename ${kea_config_file} | cut -f1 -d'.')
 
@@ -133,7 +149,7 @@ process is not running\n"
 # already running.
 start_server() {
     binary_path=${1}   # Full path to the binary.
-    binary_args="${2}" # Arguments.
+    full_command=$@    # Binary and arguments.
     # Extract the name of the binary from the path.
     local binary_name=$(basename ${binary_path})
     # Use the binary name to check if the process is already running.
@@ -143,9 +159,9 @@ start_server() {
         log_info "${binary_name} appears to be running, see: \
 PID ${_pid}, PID file: ${_pid_file}."
     else
-        log_info "Starting ${binary_name} ${args}"
+        log_info "Starting ${full_command}"
         # Start the process.
-        ${binary_path} ${args} &
+        ${full_command} &
     fi
 }
 
@@ -193,6 +209,21 @@ to process ${proc_name}, PID ${_pid}.\n"
     fi
 }
 
+### Functions testing the existence of the Kea config file
+
+# Check if the Kea configuration file location has been specified in the
+# keactrl configuration file. If not, it is a warning or a fatal error.
+check_kea_conf() {
+    local conf_file=${1} # Kea config file name.
+    if [ -z ${conf_file} ]; then
+        log_error "Configuration file for Kea not specified."
+        exit 1
+    elif [ ! -f ${conf_file} ]; then
+        log_error "Configuration file for Kea does not exist: ${conf_file}."
+        exit 1
+    fi
+}
+
 # Run the specified command if the server has been enabled.
 # In order for the command to run, the following conditions have to be met:
 # - server must be on the list of servers (e.g. specified from command line)
@@ -220,6 +251,9 @@ run_conditional() {
     # the server should be enabled or not. Variables that hold these values
     # are: ${dhcp4}, ${dhcp6}, ${dhcp_ddns}.
     local file_config=$( eval printf "%s" \${$server} )
+    # Get the location of the current Kea configuration file. This will be used
+    # to check that the file exists before it is used.
+    local kea_config_location=$( eval printf "%s" "\$kea_${server}_config_file" )
     # Run the command if we ignore the configuration setting or if the
     # setting is "yes".
     if [ ${check_file_cfg} -eq 0 ] || [ "${file_config}" = "yes" ]; then
@@ -227,21 +261,6 @@ run_conditional() {
     fi
 }
 
-### Functions testing the existence of the Kea config file
-
-# Check if the Kea configuration file location has been specified in the
-# keactrl configuration file. If not, it is a warning or a fatal error.
-check_kea_conf() {
-    local conf_file=${1} # Kea config file name.
-    if [ -z ${conf_file} ]; then
-        log_error "Configuration file for Kea not specified."
-        exit 1
-    elif [ ! -f ${conf_file} ]; then
-        log_error "Configuration file for Kea does not exist: ${conf_file}."
-        exit 1
-    fi
-}
-
 ### Script starts here ###
 
 # Configure logger to log messages into the file.
@@ -360,27 +379,24 @@ ctrl_agent=$( printf "%s" ${ctrl_agent} | tr [:upper:] [:lower:] )
 case ${command} in
     # Start the servers.
     start)
-        check_kea_conf ${kea_config_file}
-
-        args="-c ${kea_config_file}"
-
+        args=""
         if [ "${kea_verbose}" = "yes" ]; then
-            args="${args} -d"
+            args="-d"
         fi
 
         # Run servers if they are on the list of servers from the command line
         # and if they are enabled in the keactrl configuration file.
-        run_conditional "dhcp4" "start_server ${dhcp4_srv} \"${args}\"" 1
-        run_conditional "dhcp6" "start_server ${dhcp6_srv} \"${args}\"" 1
-        run_conditional "dhcp_ddns" "start_server ${dhcp_ddns_srv} \"${args}\"" 1
-        run_conditional "ctrl_agent" "start_server ${ctrl_agent_srv} \"${args}\"" 1
+        run_conditional "dhcp4" "start_server ${dhcp4_srv} -c ${kea_dhcp4_config_file} ${args}" 1
+        run_conditional "dhcp6" "start_server ${dhcp6_srv} -c ${kea_dhcp6_config_file} ${args}" 1
+        run_conditional "dhcp_ddns" "start_server ${dhcp_ddns_srv} -c ${kea_dhcp_ddns_config_file} \
+${args}" 1
+        run_conditional "ctrl_agent" "start_server ${ctrl_agent_srv} -c ${kea_ctrl_agent_config_file} \
+${args}" 1
 
         exit 0 ;;
 
     # Stop running servers.
     stop)
-        check_kea_conf ${kea_config_file}
-
         # Stop all servers or servers specified from the command line.
         run_conditional "dhcp4" "stop_server ${dhcp4_srv}" 0
         run_conditional "dhcp6" "stop_server ${dhcp6_srv}" 0
@@ -391,8 +407,6 @@ case ${command} in
 
     # Reconfigure the servers.
     reload)
-        check_kea_conf ${kea_config_file}
-
         # Reconfigure all servers or servers specified from the command line.
         run_conditional "dhcp4" "reload_server ${dhcp4_srv}" 0
         run_conditional "dhcp6" "reload_server ${dhcp6_srv}" 0
@@ -429,10 +443,16 @@ case ${command} in
             agent_status="active"
         fi
         printf "Control Agent: %s\n" ${agent_status}
-        printf "Kea configuration file: %s\n" ${kea_config_file}
+        printf "Kea DHCPv4 configuration file: %s\n" ${kea_dhcp4_config_file}
+        printf "Kea DHCPv6 configuration file: %s\n" ${kea_dhcp6_config_file}
+        printf "Kea DHCP DDNS configuration file: %s\n" ${kea_dhcp_ddns_config_file}
+        printf "Kea Control Agent configuration file: %s\n" ${kea_ctrl_agent_config_file}
         printf "keactrl configuration file: %s\n" ${keactrl_conf}
 
-        check_kea_conf ${kea_config_file}
+        check_kea_conf ${kea_dhcp4_config_file}
+        check_kea_conf ${kea_dhcp6_config_file}
+        check_kea_conf ${kea_dhcp_ddns_config_file}
+        check_kea_conf ${kea_ctrl_agent_config_file}
 
         exit 0 ;;
 

+ 12 - 9
src/bin/keactrl/tests/keactrl_tests.sh.in

@@ -16,6 +16,9 @@ keactrl=@abs_top_builddir@/src/bin/keactrl/keactrl
 CFG_FILE_NAME="test_config"
 # A name of the configuration file to be used by Kea.
 CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/${CFG_FILE_NAME}.json
+# Configuration files for all deamons.
+CFG_FILES="kea_dhcp4_config_file=${CFG_FILE}\nkea_dhcp6_config_file=${CFG_FILE}\n\
+kea_dhcp_ddns_config_file=${CFG_FILE}\nkea_ctrl_agent_config_file=${CFG_FILE}"
 # A name of the keactrl config file
 KEACTRL_CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/keactrl_test.conf
 # Path to the Kea log file.
@@ -137,7 +140,7 @@ ctrl_agent_srv=${KEACTRL_BUILD_DIR}/src/bin/agent/kea-ctrl-agent\n"
 start_all_servers_no_verbose_test() {
     # Create configuration file for keactrl. This configuration enables
     # DHCPv4, DHCPv6, D2 and CA.
-    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
+    keactrl_config="${CFG_FILES}\ndhcp4=yes\ndhcp6=yes\n\
 dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=no\n${keactrl_fixed_config}"
 
     test_start "keactrl.start_all_servers_no_verbose_test"
@@ -258,7 +261,7 @@ Expected wait_for_message return %d, returned %d."
 start_all_servers_verbose_test() {
     # Create configuration file for keactrl. This configuration enables
     # all servers.
-    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
+    keactrl_config="${CFG_FILES}\ndhcp4=yes\ndhcp6=yes\n\
 dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=yes\n${keactrl_fixed_config}"
 
     test_start "keactrl.start_all_servers_verbose_test"
@@ -376,7 +379,7 @@ Expected wait_for_message return %d, returned %d."
 start_v4_server_test() {
     # Create configuration file for keactrl. This configuration enables
     # DHCPv4 server but disables other servers.
-    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=no\n\
+    keactrl_config="${CFG_FILES}\ndhcp4=yes\ndhcp6=no\n\
 dhcp_ddns=no\nctrl_agent=no\nkea_verbose=no\n${keactrl_fixed_config}"
 
     test_start "keactrl.start_v4_server_test"
@@ -464,7 +467,7 @@ Expected wait_for_message return %d, returned %d."
 start_v6_server_test() {
     # Create configuration file for keactrl. This configuration enables
     # DHCPv6 server but disables other servers..
-    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=no\ndhcp6=yes\n\
+    keactrl_config="${CFG_FILES}\ndhcp4=no\ndhcp6=yes\n\
 dhcp_ddns=no\nctrl_agent=no\nkea_verbose=no\n${keactrl_fixed_config}"
 
     test_start "keactrl.start_v6_server_test"
@@ -552,7 +555,7 @@ Expected wait_for_message return %d, returned %d."
 late_start_v4_server_test() {
     # Create configuration file for keactrl. This configuration enables
     # DHCPv6 server but disables other servers.
-    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=no\ndhcp6=yes\n\
+    keactrl_config="${CFG_FILES}\ndhcp4=no\ndhcp6=yes\n\
 dhcp_ddns=no\nctrl_agent=no\nkea_verbose=no\n${keactrl_fixed_config}"
 
     test_start "keactrl.late_start_v4_server_test"
@@ -612,7 +615,7 @@ Expected wait_for_message return %d, returned %d."
 Expected wait_for_message to return %d, returned %d."
 
     # Update keactrl config to enable other servers.
-    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
+    keactrl_config="${CFG_FILES}\ndhcp4=yes\ndhcp6=yes\n\
 dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=yes\n${keactrl_fixed_config}"
     create_keactrl_config "${keactrl_config}"
 
@@ -715,7 +718,7 @@ Expected wait_for_message return %d, returned %d."
 late_start_v6_server_test() {
     # Create configuration file for keactrl. This configuration enables
     # DHCPv4 server but disables DHCPv6 server.
-    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=no\n\
+    keactrl_config="${CFG_FILES}\ndhcp4=yes\ndhcp6=no\n\
 dhcp_ddns=no\nctrl_agent=yes\nkea_verbose=yes\n${keactrl_fixed_config}"
 
     test_start "keactrl.late_start_v6_server_test"
@@ -775,7 +778,7 @@ Expected wait_for_message return %d, returned %d."
 Expected wait_for_message to return %d, returned %d."
 
     # Update keactrl config to enable other servers.
-    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
+    keactrl_config="${CFG_FILES}\ndhcp4=yes\ndhcp6=yes\n\
 dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=no\n${keactrl_fixed_config}"
     create_keactrl_config "${keactrl_config}"
 
@@ -877,7 +880,7 @@ Expected wait_for_message return %d, returned %d."
 stop_selected_server_test() {
     # Create configuration file for keactrl. This configuration enables
     # all servers.
-    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
+    keactrl_config="${CFG_FILES}\ndhcp4=yes\ndhcp6=yes\n\
 dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=no\n${keactrl_fixed_config}"
 
     test_start "keactrl.stop_selected_server_test"