# is to determine whether the keactrl command belongs to the list of
# supported commands.
is_in_list() {
- local member=${1} # Value to be checked
- local list="${2}" # Comma separated list of items
+ member=${1} # Value to be checked
+ list="${2}" # Comma separated list of items
_inlist=0 # Return value: 0 if not in list, 1 otherwise.
if [ -z "${member}" ]; then
log_error "missing ${member}"
# Prints keactrl usage.
usage() {
- printf "usage is %s command [-c keactrl-config-file] [-s server[,server,..]]\n" $( basename ${0} )
+ printf "usage is %s command [-c keactrl-config-file] [-s server[,server,..]]\n" "$( basename ${0} )"
printf "commands: start stop reload status version\n"
}
# be read the function exists with a error message. Note the PID file name
# is always returned in $_pid_file.
get_pid_from_file() {
- local proc_name=${1} # Process name.
+ proc_name=${1} # Process name.
- local kea_config_file=
+ kea_config_file=
case ${proc_name} in
kea-dhcp4)
kea_config_file=${kea_dhcp4_config_file}
esac
# Extract the name portion of the config file
- local conf_name=$(basename "${kea_config_file}" | cut -f1 -d'.')
+ conf_name=$(basename "${kea_config_file}" | cut -f1 -d'.')
# Default the directory to --localstatedir
- local pid_file_dir=@localstatedir@/@PACKAGE@
+ pid_file_dir=@localstatedir@/@PACKAGE@
# Use directory override if set (primarily for testing only)
- if [ ! -z $KEA_PIDFILE_DIR ]; then
+ if [ ! -z "$KEA_PIDFILE_DIR" ]; then
pid_file_dir=${KEA_PIDFILE_DIR}
fi
_pid_file="${pid_file_dir}/${conf_name}.${proc_name}.pid"
# Grab the PID if the file exists
- if [ -e ${_pid_file} ]; then
- _pid=`cat ${_pid_file}`
+ if [ -e "${_pid_file}" ]; then
+ _pid=$(cat ${_pid_file})
if [ $? -ne 0 ]; then
log_error "Error reading PID file: ${_pid_file}"
fi
# PID file and checking the PID it contains. If the file does
# not exist, the process is assumed to not be running.
check_running() {
- local proc_name=${1} # Process name.
+ proc_name=${1} # Process name.
# Initially mark the process as not running.
_running=0
# Sends a signal to a process based on its PID file
send_signal() {
- local sig=${1} # Signal number
- local proc_name=${2} # Process name.
+ sig=${1} # Signal number
+ proc_name=${2} # Process name.
get_pid_from_file ${proc_name}
if [ ${_pid} -eq 0 ]; then
log_info "Skip sending signal ${sig} to process ${proc_name}: \
process is not running\n"
else
- kill -${sig} ${_pid}
+ kill "-${sig}" "${_pid}"
if [ $? -ne 0 ]; then
log_error "Failed to send signal ${sig} to process ${proc_name}, PID {$_pid}.\n"
fi
binary_path=${1} # Full path to the binary.
full_command=$@ # Binary and arguments.
# Extract the name of the binary from the path.
- local binary_name=$(basename ${binary_path})
+ binary_name=$(basename "${binary_path}")
# Use the binary name to check if the process is already running.
- check_running ${binary_name}
+ check_running "${binary_name}"
# If process is running, don't start another one. Just log a message.
if [ ${_running} -ne 0 ]; then
log_info "${binary_name} appears to be running, see: \
# Instruct Kea process to shutdown by sending it signal 15
stop_server() {
binary_path=${1} # Full path to the binary.
- local sig=15
+ sig=15
# Extract the name of the binary from the path.
- local binary_name=$(basename ${binary_path})
+ binary_name=$(basename "${binary_path}")
# Use the binary name to check if the process is already running.
- check_running ${binary_name}
+ check_running "${binary_name}"
# If process isn't running, don't start another one. Just log a message.
if [ ${_running} -eq 0 ]; then
log_info "${binary_name} isn't running."
# Instruct Kea process to reload config by sending it signal 1
reload_server() {
binary_path=${1} # Full path to the binary.
- local sig=1
+ sig=1
# Extract the name of the binary from the path.
- local binary_name=$(basename ${binary_path})
+ binary_name=$(basename "${binary_path}")
# Use the binary name to check if the process is already running.
check_running ${binary_name}
name=${1}
binary_path=${2}
- if [ -e ${binary_path} ]; then
- ver=`${binary_path} -v`
+ if [ -e "${binary_path}" ]; then
+ ver=$(${binary_path} -v)
if [ $? -ne 0 ]; then
log_error "Error checking version of binary file: ${binary_path}"
fi
# 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
+ if [ -z "${conf_file}" ]; then
log_error "Configuration file for Kea not specified."
exit 1
- elif [ ! -f ${conf_file} ]; then
+ elif [ ! -f "${conf_file}" ]; then
log_error "Configuration file for Kea does not exist: ${conf_file}."
exit 1
fi
# and be set to yes, e.g. ${dhcp4} should be equal to yes if server name
# is dhcp4
run_conditional() {
- local server=${1} # Server name: dhcp4, dhcp6, dhcp_ddns, ctrl_agent, netconf
- local commands="${2}" # Commands to execute
- local check_file_cfg=${3} # Check if server enabled in the configuration file
- local is_all=0 # is all servers or a specific one
+ server=${1} # Server name: dhcp4, dhcp6, dhcp_ddns, ctrl_agent, netconf
+ commands="${2}" # Commands to execute
+ check_file_cfg=${3} # Check if server enabled in the configuration file
+ is_all=0 # is all servers or a specific one
# If keyword "all" is not on the list of servers we will have to check
# if our specific server is on the list. If, not return.
is_in_list "all" "${servers}"
if [ ${_inlist} -eq 0 ]; then
- is_in_list ${server} "${servers}"
+ is_in_list "${server}" "${servers}"
if [ ${_inlist} -eq 0 ]; then
return
fi
is_all=1
fi
# Return for for netconf when not available.
- if [ ${server} = "netconf" ]; then
- if [ ${have_netconf} -eq 0 ]; then
+ if [ "${server}" = "netconf" ]; then
+ if [ "${have_netconf}" -eq 0 ]; then
return
fi
# reload is not supported for netconf.
# Get the configuration value of the keactrl which indicates whether
# the server should be enabled or not. Variables that hold these values
# are: ${dhcp4}, ${dhcp6}, ${dhcp_ddns}.
- local file_config=$( eval printf "%s" \${$server} )
+ 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" )
+ kea_config_location=$( eval printf "%s" "\$kea_${server}_config_file" )
# Run the commands if we ignore the configuration setting or if the
# setting is "yes".
- if [ ${check_file_cfg} -eq 0 ] || [ "${file_config}" = "yes" ]; then
+ if [ "${check_file_cfg}" -eq 0 ] || [ "${file_config}" = "yes" ]; then
${commands}
fi
}
# Note that when the configuration is applied this location may be
# altered and only the handful of initial messages will be logged
# to the default file.
-if [ -z ${KEA_LOGGER_DESTINATION} ]; then
+if [ -z "${KEA_LOGGER_DESTINATION}" ]; then
prefix=@prefix@
export KEA_LOGGER_DESTINATION=@localstatedir@/@PACKAGE@/kea.log
fi
command=${1}
-if [ -z ${command} ]; then
+if [ -z "${command}" ]; then
log_error "missing command"
usage
exit 1
-c|--ctrl-config)
shift
keactrl_conf=${1}
- if [ -z ${keactrl_conf} ]; then
+ if [ -z "${keactrl_conf}" ]; then
log_error "keactrl-config-file not specified"
usage
exit 1