#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: "Try to start multiple s4-connector instances"
## exposure: dangerous
## packages:
## - univention-s4-connector

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

. "s4connector.sh" || exit 137
test -n "$connector_s4_ldap_host" || exit 137
connector_running_on_this_host || exit 137

echo "Check for a running connector"
pgrep -f "/usr/bin/python3 -W ignore -m univention.s4connector.s4.main" || fail_test 1

echo "Try to start a second connector instance"
/usr/bin/python3 -W ignore -m univention.s4connector.s4.main && fail_test 110

if [ "$RETVAL" = 110 ]; then
	pkill -f "/usr/bin/python3 -W ignore -m univention.s4connector.s4.main"
	/etc/init.d/univention-s4-connector restart
fi

exit $RETVAL
