Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > main-src > by-pkgid > 5bfb117ec26d438c806f42f3723d6c76 > files > 13

openldap-2.0.21-4mdk.src.rpm

#!/bin/sh
#
# ldap	This shell script takes care of starting and stopping
#	ldap servers (slapd and slurpd).
#
# chkconfig: 345 39 61
# description: LDAP stands for Lightweight Directory Access Protocol, used \
#              for implementing the industry standard directory services.
# processname: slapd
# config: /etc/openldap/slapd.conf
# pidfile: /var/run/ldap/slapd.pid
#
# Created by Christian Zoffoli <czoffoli@linux-mandrake.com>
# Version 0.1b  2001-05-23
#

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

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Source an auxiliary options file if we have one, and pick up OPTIONS,
# SLAPD_OPTIONS, and SLURPD_OPTIONS.
if [ -r /etc/sysconfig/ldap ] ; then
	. /etc/sysconfig/ldap
fi

slapd=/usr/sbin/slapd
slurpd=/usr/sbin/slurpd
[ -x ${slapd} ] || exit 0
[ -x ${slurpd} ] || exit 0


check_slurpd() {
	if grep -q "^replogfile" /etc/openldap/slapd.conf; then
		return 0
	fi

	return 1
}


start() {
	local RETVAL=0
	local RETVAL2=0
	local ARGS=""

    # Start daemons.
	ARGS="-u ldap -g ldap"

	# Syslog 
	if [ -n "$SLAPDSYSLOGLOCALUSER" ] ; then
		ARGS="$ARGS -l $SLAPDSYSLOGLOCALUSER"
		if [ -n "$SLAPDSYSLOGLEVEL" ] ; then
			ARGS="$ARGS -s $SLAPDSYSLOGLEVEL"
		fi
	fi
	
	OUT="ldap"
	if [ -n "$SLAPDURLLIST" ] ; then
		if echo $SLAPDURLLIST | grep -q "ldaps" && grep -q "^TLS" /etc/openldap/slapd.conf  ; then
			ARGS="$ARGS -h \"$SLAPDURLLIST\""
			OUT="ldap + ldaps"
			if [ ! -e /etc/openldap/ldap.pem ] ; then
				if [ -x /usr/share/openldap/gencert.sh ] ; then
						echo "Generating self-signed certificate"
						pushd /etc/openldap/ > /dev/null
						yes ""|/usr/share/openldap/gencert.sh >/dev/null 2>/dev/null
					    popd > /dev/null
				fi
			fi
			echo -e "\n To generate a self-signed certificate, you can use"
			echo -e " the utility /usr/share/openldap/gencert.sh ...\n"

			if ls /var/lib/ldap/*.gdbm > /dev/null 2>/dev/null || :  ; then
				echo -e " To convert a gdbm DB to a ldif file, you can use"
				echo -e " the utility /usr/sbin/slapcat-gdbm (actually openldap use "
				echo -e " Berkeley DB 3.x)...\n"
			fi
		else
			ARGS="$ARGS -h \"ldap:/// \""

		fi
	else
		ARGS="$ARGS -h \"ldap:/// \""
	fi

        echo -n $"Starting slapd ($OUT): "
	daemon ${slapd} $ARGS
	RETVAL=$?
	echo

	if [ $RETVAL -eq 0 ]; then
            if check_slurpd ; then
		echo -n $"Starting slurpd: "
                daemon ${slurpd} 
		RETVAL2=$?
		echo
            fi
	fi
	[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && touch /var/lock/subsys/ldap || RETVAL=1
        return $RETVAL
}

stop() {
	local RETVAL=0
	local RETVAL2=0

        # Stop daemons.
	echo -n $"Stopping slapd: "
	killproc ${slapd}
	RETVAL=$?
	echo

	if [ $RETVAL -eq 0 ]; then
	    if check_slurpd ; then
		echo -n $"Stopping slurpd: "
		killproc ${slurpd}
		RETVAL2=$?
		echo
	    fi
	fi
        [ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && rm -f /var/lock/subsys/ldap /var/run/ldap/slapd.args
	return $RETVAL
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status ${slapd}
        if check_slurpd ; then
            status ${slurpd}
	fi
	;;
    restart)
	stop
	start
	;;
    reload)
    	killall -HUP ${slapd}
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
	    if check_slurpd ; then
		killall -HUP ${slurpd}
		RETVAL=$?
	    fi
	fi
	;;
    condrestart)
        if [ -f /var/lock/subsys/ldap ] ; then
            stop
            start
        fi
	;;
    *)
	echo $"Usage: $0 {start|stop|restart|status|condrestart}"
	RETVAL=1
esac

exit $RETVAL