#!/bin/sh
# Jesús Pérez Lorenzo 
# Wrap arround to star-up LDAP servers ...

USAGE="open-ldap [ LDAPNAME ]   [ start | stop | etc ... ] "

ldapName="ALL";
case "$1" in 
         start|stop|status|try-restart|restart|force-reload|reload) ;;
         *) ldapName=$1; shift ;;
esac
CMD_ARGS="$*";

# debug level
DEBUG_LDAP=" -d 256 -s error -s debug -s info" 
#DEBUG_LDAP=" -d 1024 -s error -s debug -s info" 

HOSTNAME=`hostname`

function main() {
	#cmd_forldap ttaldap "$HOSTNAME:389"
	cmd_forldap ttaldap2 "$HOSTNAME:16634"

	#cmd_forldap ttacache "$HOSTNAME:802"
	cmd_forldap ttacache2 "$HOSTNAME:6889"
}

function cmd_forldap() {
   # getting $1 for LDAPNAME and  $2 for hostname:port
   if  [ "$ldapName" != "ALL"  -a  "$ldapName" != "$1" ]  ; then 
         return
   fi
   LDAPNAME="$1 $2"
   LDAP_ARGS=" -f /etc/openldap/$1.conf -h  ldap://$2/ $DEBUG_LDAP"
   export LDAPNAME LDAP_ARGS
   /etc/init.d/open-ldap $CMD_ARGS 
}
    
main;
