#!/bin/sh
#
#
# 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.
#

set -e 

if test "x$MASTER" != "x$HOST" || test "x$BACKUP" = "x"; then
  echo "Ignoring $0 for failover"
  exit $IGNORE
fi

if test "x$DEBUG" != "x"; then
  set -ex
fi

eval `ultrapossum-config get SYSCONFDIR`

cat >$TMPFILE <<EOF
dn: ou=add,$SUFFIX
objectClass: top
objectClass: organizationalUnit
ou: add
EOF

date
/etc/init.d/heartbeat stop

(
 for i in 0 1 2 3 4 5 6 7 8 9
 do
   if ldapadd -x -h $BACKUP -D $ROOTDN -w $ROOTPW -f $TMPFILE; then
     exit 0
   fi
   sleep 1
 done
 exit 1
) || exit 1
date

exit $OK
