#!/bin/sh
#
# ldap	This shell script takes care of starting and stopping
#	OPENLDAP servers (slapd).
#
# chkconfig: 345 39 61
#
# description:	LDAP stands for Lightweight Directory Access Protocol, used
#               for implementing the industry standard directory services.
#
# processname: slapd
#
# Version 3.1.1 for OpenLDAP 2.1.22
# (modify by vserge For ALT Linux Team Sisyphus)
#
# From version of this script 3.1.0 SLURPD removed to different script
#

WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
# Check that networking is up.
SourceIfNotEmpty /etc/sysconfig/network

# Source an auxiliary options file if we have one, and pick up OPTIONS,
# SLAPD_OPTIONS.
SourceIfNotEmpty /etc/sysconfig/ldap

SLAPD=/usr/sbin/slapd
CONFIG=/etc/openldap/slapd.conf

[ -x "$SLAPD" -a -s "$CONFIG" ] || exit

PIDFILE=/var/run/slapd.pid
RETVAL=0

start()
{
	is_yes "$NETWORKING" || return 0
	start_daemon --pidfile "$PIDFILE" $SLAPD $SLAPDURLLIST
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" $SLAPD
	RETVAL=$?
	return $RETVAL
}

reload()
{
	msg_reloading $SLAPD
	stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP $SLAPD
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

check()
{
	$SLAPD -t 
	echo_success
	RETVAL=$?
	return $RETVAL
	
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root $SLAPD
		RETVAL=$?
		;;
	restart)
		restart
		;;
	checkconfig)
		check
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	*)
		msg_usage "${0##*/} {start|stop|status|checkconfig|restart|condstop|condrestart}"
		RETVAL=1
esac

exit $RETVAL

