#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: Restarting Nagios doesn't shutdown the old Instance of Nagios
## bugs: [10849]
## tags: [basic]
## packages:
##  - univention-directory-manager-tools
##  - univention-nagios-server
##  - univention-nagios-client
## exposure: careful

# shellcheck source=../../lib/base.sh
. "$TESTLIBPATH/base.sh" || exit 137

###################
###  Information  #
###################
### This script tests, if there is only one instance of Nagios after a restart of Nagios
###################

set -x

trap "service nagios stop; pkill nagios; service nagios start" EXIT

# ensure nagios is started
if [ "$(pgrep -c nagios)" -eq 0 ]; then
	service nagios start
	sleep 3
fi
nagios_pid="$(nagiostats | VAL1 'Nagios PID')"

# restart Nagios
echo "Restarting Nagios"
service nagios restart
sleep 3
new_nagios_pid="$(nagiostats | VAL1 'Nagios PID')"

# make sure old pid is no longer running
[ -d "/proc/$nagios_pid" ] && exit 111
[ ! -d "/proc/$new_nagios_pid" ] && exit 111

exit 101
# vim:set filetype=sh ts=4:
