|
@@ -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 ;;
|
|
|
|