#!/bin/sh

# Copyright \302\251 2004 Sun Microsystems, Inc. All rights reserved.
#
# Sun Microsystems, Inc. has intellectual property rights relating to
# technology embodied in the product that is described in this document.
# In particular, and without limitation, these intellectual property rights
# may include one or more of the U.S. patents listed at
# http://www.sun.com/patents and one or more additional patents or pending
# patent applications in the U.S. and in other countries.
#
# U.S. Government Rights - Commercial software. Government users are subject
# to the Sun Microsystems, Inc. standard license agreement and applicable
# provisions of the FAR and its supplements.
#
# Use is subject to license terms.
#
# This distribution may include materials developed by third parties. Sun,
# Sun Microsystems, the Sun logo, Java and Sun[tm] ONE are trademarks or
# registered trademarks of Sun Microsystems, Inc. in the U.S. and other
# countries.
#
# Copyright \302\251 2004 Sun Microsystems, Inc. Tous droits r\303\251serv\303\251s. Sun
# Microsystems, Inc. d\303\251tient les droits de propri\303\251t\303\251 intellectuels relatifs
# \303\240 la technologie incorpor\303\251e dans le produit qui est d\303\251crit dans ce document.
# En particulier, et ce sans limitation, ces droits de propri\303\251t\303\251
# intellectuelle peuvent inclure un ou plus des brevets am\303\251ricains list\303\251s
# \303\240 l'adresse http://www.sun.com/patents et un ou les brevets suppl\303\251mentaires
# ou les applications de brevet en attente aux Etats - Unis et dans les
# autres pays.
#
# L'utilisation est soumise aux termes du contrat de licence.
#
# Cette distribution peut comprendre des composants d\303\251velopp\303\251s par des
# tierces parties.
#
# Sun, Sun Microsystems, le logo Sun, Java et Sun[tm] ONE sont des marques
# de fabrique ou des marques d\303\251pos\303\251es de Sun Microsystems, Inc. aux
# Etats-Unis et dans d'autres pays.

JAVA_HOME=/usr/jdk/entsys-j2se

OS_ARCH=`/bin/uname -s`

IMQ_JAR_PATH=/usr/share/lib
JMS_JAR_PATH=/usr/share/lib
BDB_JAR_PATH=/usr/share
BDB_SO_PATH=/usr/lib
AM_HOME=/opt/SUNWam

if [ "$OS_ARCH" = "Linux" ]; then
	IMQ_JAR_PATH=/opt/sun/mq/share/lib
	JMS_JAR_PATH=/opt/sun/mq/share/lib
	BDB_JAR_PATH=/usr/share/bdb
	BDB_SO_PATH=/opt/sun/private/lib
	AM_HOME=/opt/sun/identity
fi




CLASSPATH=${IMQ_JAR_PATH}/imq.jar:${JMS_JAR_PATH}/jms.jar:${BDB_JAR_PATH}/db.jar:${AM_HOME}/locale:${AM_HOME}/lib/am_sessiondb.jar:.

OS_ARCH=`/bin/uname -s`

if [ -z "$LD_LIBRARY_PATH" ] ; then
	LD_LIBRARY_PATH=${BDB_SO_PATH}
else
	LD_LIBRARY_PATH=${BDB_SO_PATH}:$LD_LIBRARY_PATH
fi

if [ "$OS_ARCH" = "Linux" ]; then
	LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${JAVA_HOME}/jre/lib/i386/native_threads
fi

export LD_LIBRARY_PATH

JAVA_OPTS="-Xms128m -Xmx512m -Dsleepycat.db.libname=db_java"
RESTART=true


shutdown_amsessiondb() {
    RESTART=false
    if [ -n "$_javapid" ]; then
        kill -TERM $_javapid
    fi
    echo "done. \n"
}

# If the script process is killed make sure we shutdown the Broker's Java process
trap "shutdown_amsessiondb" TERM INT QUIT

RESTART=true
while [ "$RESTART" = "true" ]; do
     echo "Starting...  $RESTART" >> /tmp/test
    _javapid=""
     echo "$JAVA_HOME/bin/java $JAVA_OPTS -classpath $CLASSPATH com.iplanet.dpro.session.jmqdb.client.AMSessionDB"
     $JAVA_HOME/bin/java $JAVA_OPTS -classpath "$CLASSPATH" com.iplanet.dpro.session.jmqdb.client.AMSessionDB "$@" &
    _javapid=$!
    wait $_javapid
    _status=$?

    if [ $_status -eq 0 -o $_status -eq 1 -o $_status -eq 129 -o $_status -eq 130 -o $_status -eq 143 ]; then
        RESTART=false
    elif [ "$AM_SFO_RESTART" = "true" ]; then
        RESTART=true
    else
        RESTART=false
    fi

done

