#!/bin/sh
#
# Set up environment to run the LibMON server and start it.
# Set up environment to run the license server and start it.
#
# NOTE: Be careful when editing this file. Leave no whitespaces
#       after any of the continuation backslashes '\'
#
# __BASEDIR__ will get substituted after installation
#

#
# Set up the top and base directories
#
BASEDIR=__BASEDIR__
TOP=${BASEDIR}/SUNWlmon

#
# Set up the commands to use
#
CAT=/usr/bin/cat
NOHUP=/usr/bin/nohup
SLEEP=/usr/bin/sleep
SLEEPTIME=3

#
# Set up the CLASSPATH
#
CLASSPATH=${TOP}/JRE/lib/rt.jar:${TOP}/JRE/lib/i18n.jar:${TOP}/classes/SUNWlmon.zip: 
export CLASSPATH

#
# Set up the SCSI_FORMATTER_PATH
#
SCSI_FORMATTER_PATH=${TOP}/bin 
export SCSI_FORMATTER_PATH

#
# Set up the PATH
#
PATH=/opt/LWperl5/bin                       # PERL Path
PATH=${PATH}:/bin:/usr/bin:/usr/ucb:/etc:.: # Standard Command Path
export PATH

#
# Run the command 
#
if [ $# -eq 0 ]; then 

    # Start the server normally
    echo "Starting LibMON server ..."
    ${NOHUP} ${TOP}/JRE/bin/jre \
             -D"atl.serverInstallDir=${TOP}" \
             atl.server.Server > ${TOP}/LibMON.log 2>&1 &

    # Save the pid
    echo $! > ${TOP}/LibMON.pid 

    # Display any errors from the log
    ${SLEEP} ${SLEEPTIME}
    ${CAT} ${TOP}/LibMON.log 

elif [ -n "$1" -a "$1" = "-debug" -a -z "$2" ]; then

    # Start the server in "debug" mode 
    # Dumps output to the screen, not in nohup mode
    echo "Starting LibMON server in debug mode ..."
    ${TOP}/JRE/bin/jre -D"atl.serverInstallDir=${TOP}" atl.server.Server &

    # Save the pid
    echo $! > ${TOP}/LibMON.pid 

elif [ -n "$1" -a "$1" = "-dup" -a -z "$2" ]; then

    # Start the server in "dup" mode 
    echo "Starting LibMON server allowing duplicate device names ..."
    ${NOHUP} ${TOP}/JRE/bin/jre \
             -D"atl.serverInstallDir=${TOP}" \
             -D"atl.allow.duplicates=YES" \
             atl.server.Server > ${TOP}/LibMON.log 2>&1 &

    # Save the pid
    echo $! > ${TOP}/LibMON.pid 

    # Display any errors from the log
    ${SLEEP} ${SLEEPTIME}
    ${CAT} ${TOP}/LibMON.log 

elif [ -n "$1" -a "$1" = "-v" -a -z "$2" ]; then

    # Start the server with the -v flag 
    ${TOP}/JRE/bin/jre -D"atl.serverInstallDir=${TOP}" atl.server.Server $1

else

    echo "Usage: $0 [-v] | [-dup]"

fi
