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'.')
# 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.
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
}
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)
# 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
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.
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
# 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
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 ;;
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.
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"
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"
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"
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"
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"
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}"
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"
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}"
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"