#!/bin/sh
#
# qmail		This shell script takes care of starting and stopping qmail.
#
# chkconfig:	2345 80 30
#
# description:	Qmail is a Mail Transport Agent, which is the program \
#		that moves mail from one machine to another.


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

# Get network config
. /etc/sysconfig/network

# Get service config
#[ -f /etc/sysconfig/qmail ] && . /etc/sysconfig/qmail

# Check that networking is up.
RETVAL=0

# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/powermail-ldap ]; then
		PATH="/var/qmail/ldap/scripts:/usr/local/libexec:/usr/local/bin:/usr/local/sbin:$PATH"; export PATH

		start-ldap /var/qmail/ldap 
		sleep 1

		if ps ax | grep -v grep | grep -q slapd
		then
			touch /var/lock/subsys/powermail-ldap
			echo "powermail ldap server is running"
		else
			RETVAL=1
		fi
	else
		echo "powermail ldap server is already running"
		exit 1
	fi
	;;
  stop)
	# Stop daemons.
	killproc slapd
	rm -f /var/lock/subsys/powermail-ldap
	;;
  restart|reload)
  	$0 stop
	$0 start
	;;
  status)
  	status slapd
	;;
  *)
	msg_Usage "$0 {start|stop|status|restart|reload}"
	exit 1
esac

exit $RETVAL
