#!/bin/sh
#
# slurpd	This shell script takes care of starting and stopping
#	       OpenLDAP replication servers (slurpd).
#
# chkconfig: 345 39 61
#
# description:	LDAP stands for Lightweight Directory Access Protocol, used
#               for implementing the industry standard directory services.
#
# processname: slurpd
# config: /etc/openldap/
# pidfile: /var/run/slapd.pid
#
# 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
#

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

# Source networking configuration.
SourceIfNotEmpty /etc/sysconfig/network

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

DAEMON=/usr/sbin/slurpd
ROOT=/var/lib/ldap
CONFIG=/etc/openldap/slapd.conf
LOCKFILE=/var/lock/subsys/slurpd
PIDFILE=$ROOT/var/run/slurpd.pid
RETVAL=0

check()
{
	grep ^replogfile $CONFIG > /dev/null || return 1
	grep ^replica $CONFIG > /dev/null || return 1
}

start()
{
	is_yes "$NETWORKING" || return 0
	check || return
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" -- $DAEMON -u ldap -c $ROOT "$SLURPD_OPTIONS"
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user ldap $DAEMON
	RETVAL=$?
	return $RETVAL
}

reload()
{
	msg_reloading $DAEMON
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user ldap -HUP $DAEMON
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	sleep 2
	start
}

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

exit $RETVAL
