# Wait for file to be created.
wait_for_file() {
local file=${1}
- timeout='4' # seconds
- deadline=$(($(date +%s) + timeout))
+ local timeout='4' # seconds
+ local deadline=$(($(date +%s) + timeout))
while ! test -f "${file}"; do
if test "${deadline}" -lt "$(date +%s)"; then
# Time is up.
}
# Wait for process identified by PID to die.
-wait_for_process_to_die() {
+wait_for_process_to_stop() {
local pid=${1}
- timeout='4' # seconds
- deadline=$(($(date +%s) + timeout))
+ local timeout='4' # seconds
+ local deadline=$(($(date +%s) + timeout))
while ps "${pid}" >/dev/null; do
if test "${deadline}" -lt "$(date +%s)"; then
# Time is up.
- printf 'ERROR: %s does not want to die.\n' "$(get_process_name "${pid}")" >&2
+ printf 'ERROR: %s is not stopping.\n' "$(get_process_name "${pid}")" >&2
return 1
fi
- printf 'Waiting for %s to die...\n' "$(get_process_name "${pid}")"
+ printf 'Waiting for %s to stop...\n' "$(get_process_name "${pid}")"
sleep 1
done
}
kill_processes_by_name() {
local proc_name=${1} # Process name
if [ -z "${proc_name}" ]; then
- test_lib_error "get_pids requires process name"
+ test_lib_error "kill_processes_by_name requires process name"
clean_exit 1
fi
+
# Obtain PIDs of running processes.
local pids
pids=$(pgrep "${proc_name}" || true)
printf 'Shutting down Kea process %s with PID %d...\n' "${proc_name}" "${pid}"
kill -9 "${pid}" || true
done
+
+ # Wait for all processes to stop.
+ for pid in ${pids}; do
+ printf 'Waiting for Kea process %s with PID %d to stop...\n' "${proc_name}" "${pid}"
+ wait_for_process_to_stop "${pid}"
+ done
}
# Returns the number of occurrences of the Kea log message in the log file.