#!/bin/sh

. ${HEALTHCHECK_SCRIPTS:-/usr/share/openstack-tripleo-common/healthcheck}/common.sh

process='dnsmasq'
if pgrep $process; then
	listen_address=$(get_config_val /etc/ironic-inspector/inspector.conf DEFAULT listen_address 127.0.0.1)
	# Check DHCPv6 port if using IPv6
	if [[ $listen_address =~ ":" ]]; then
		port="547"
	else
		port="67"
	fi
	echo "Checking $process port(s) $port."
	if ! healthcheck_port $process $port; then
		echo "There is no $process process listening on port(s) $port in the container."
		exit 1
	fi
else
	bind_host=$(wrap_ipv6 $(get_config_val /etc/ironic-inspector/inspector.conf DEFAULT listen_address 127.0.0.1))
	bind_port=$(get_config_val /etc/ironic-inspector/inspector.conf DEFAULT listen_port 5050)
	healthcheck_curl http://${bind_host}:${bind_port}
fi
