#!/usr/bin/env bash
#
# Copyright (C) 2003 VA Linux Systems Japan, K.K.
#
# LICENSE NOTICE
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#

#
# $Id: ldap,v 1.2 2004/03/25 03:25:09 taru Exp $
#

set -e

eval `ultrapossum-config init`
trap "eval `ultrapossum-config term`" 0

# Source function library.
. $HA_DIR/shellfuncs

ldap_start () {

    ha_log "info: $0: Starting"

    if test "x$NFSDIR" != "x" && ! include "$BACKUP" "$SYNCBACKUPS"; then
      $MODULEDIR/failover/recovery
    fi

    $MODULEDIR/server/startup master_start

}

ldap_stop () {
    ha_log "info: $0: Shutting down"
    $MODULEDIR/server/startup master_stop
    if test "x$HOST" = "x$BACKUP" && ! include "$BACKUP" "$SYNCBACKUPS"; then
      ha_log "starting slave slapd"
      ldapslave_start
    fi
}

# See how we were called.
case "$1" in
  start)
        ldap_start
        ;;
  stop)
        ldap_stop
        ;;
  restart)
        ldap_stop
        ldap_start
        ;;
  status)
        $MODULEDIR/server/startup master_status
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac
exit 0
