#!/bin/sh
### BEGIN INIT INFO
# Provides:          univention-s4-connector
# Required-Start:    $network $remote_fs slapd samba-ad-dc
# Required-Stop:     $network $remote_fs slapd samba-ad-dc
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Univention S4 Connector
### END INIT INFO
# pidfile: /var/run/univention-s4-connector
#
# SPDX-FileCopyrightText: 2004-2026 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

S4CONNECTORPID=/var/run/univention-s4-connector
NAME='univention-s4-connector'
DAEMON="/usr/sbin/univention-s4-connector"

test -x "$DAEMON"|| exit 0

. /lib/lsb/init-functions
DESC=$(get_lsb_header_val "$0" Short-Description)

case "$1" in
	start)
		# check ucr autostart setting
		if [ -f "/usr/share/univention-config-registry/init-autostart.lib" ]; then
			. "/usr/share/univention-config-registry/init-autostart.lib"
			check_autostart s4-connector connector/s4/autostart
		fi
		log_daemon_msg "Starting $DESC" "$NAME"
		start-stop-daemon --start --oknodo --quiet --pidfile "$S4CONNECTORPID" --startas "$DAEMON"
		log_end_msg $?
		;;
	stop)
		log_daemon_msg "Stopping $DESC" "$NAME"
		start-stop-daemon --stop --oknodo --retry TERM/300/KILL/5 --quiet --pidfile "$S4CONNECTORPID"
		log_end_msg $?
		;;
	restart|force-reload)
		"$0" stop
		sleep 2 # give it some time to die
		"$0" start
		;;
	status)
		status_of_proc -p "$S4CONNECTORPID" "$DAEMON" "$DESC"
		;;
	crestart)
		pidofproc -p "$S4CONNECTORPID" "$DAEMON" && "$0" restart
		;;
	*)
		echo "Usage: $0 {start|stop|restart|crestart|force-reload|status}"
		exit 1
		;;
esac
