#!/bin/bash
# 
# DISCLAIMER
#   Trigo Technologies, Inc. disclaims all warranties or representations herein,
#   whether express, implied or statutory, to the fullest extent
#   permissible by law, including the implied warranties of title,
#   fitness for a particular purpose and merchantability.
# 
# COPYRIGHTS
#   Copyright 2001, 2002 Trigo Technologies, Inc. All rights reserved.
# 
#   Trigo Technologies, Inc.
#   8000 Marina Blvd, Suite 810
#   Brisbane, CA 94005
#   U.S.A.
#   www.trigo.com
# 
# TRADEMARKS
#   Trigo, Trigo Enterprise, Trigo Content Suite, Trigo Commerce Suite,
#   and Trigo Platform are trademarks of Trigo Technologies, Inc.
#   All other company and product names are trademarks or registered
#   trademarks of their respective owners.
#


. ${TOP}/bin/get_params.sh
SVC_NAME=${_TRIGO_SVC_NAME=appsvr_${SHORT_HOSTNAME}}
. ${ADMIN_DIR}/init_svc_vars.sh

if [ ! "${_TRIGO_STOP}" = "no" ]; then
    ${ADMIN_DIR}/abort/abort_appsvr.sh --svc_name=${SVC_NAME}
fi

${ECHO} "starting service '${SVC_NAME}'"
cd $TOP


# now start the right java process
case "${TRIGO_APPSVR}" in
    tomcat33)
        InitEtcDirForAppSvr tomcat33
        # the 'cd' is only for a the dtds...
        # no need to be service specific
        cd ${SVC_ETC_DIR}/tomcat33
        ${RM} ${TOP}/logs/${SVC_NAME}/tomcat/work/*

        EXTRA_APPSVR_VARS="-DTRIGO_HOSTNAME=${SHORT_HOSTNAME} -DTRIGO_APPSVR_PORT=${_TRIGO_CONF_APPSVR_PORT} -DTRIGO_TOMCAT_AJP12=${_TRIGO_CONF_TOMCAT_AJP12} -DTRIGO_TOMCAT_AJP13=${_TRIGO_CONF_TOMCAT_AJP13}"
        APPSVR_OPTS="${APPSVR_OPTS} ${EXTRA_APPSVR_VARS}"

        startWithLogs ${JDK_HOME}/bin/java \
            ${APPSVR_OPTS} \
            ${TRIGO_APPSVR_JVM_DEBUG_OPTS}\
            -classpath ${TRIGO_CLASSPATH} \
            -Dtomcat.home=${TOMCAT_HOME} \
            ${TRIGO_APPSVR_JVM_PROFILING_OPTS}\
            org.apache.tomcat.startup.Main \
            -f ${SVC_ETC_DIR}/tomcat33/server.xml
        ;;

    weblogic700)
        InitEtcDirForAppSvr weblogic700
        cd ${WL_HOME}/server/bin
        export CLASSPATH=
        . ./setWLSEnv.sh
        export CLASSPATH=${TRIGO_CLASSPATH}${PATH_SEPARATOR}${CLASSPATH}
        cd ${TRIGO_WL_DOMAIN_DIR}

        STARTMODE=true
        BEA_HOME=`cd ${WL_HOME}/..; pwd`
        APPSVR_OPTS="${APPSVR_OPTS} -Dtrigo_wl_pw=${TRIGO_WL_PW}"

        startWithLogs ${JDK_HOME}/bin/java \
            ${APPSVR_OPTS} \
            ${TRIGO_APPSVR_JVM_DEBUG_OPTS}\
            -classpath ${CLASSPATH} \
            -Dweblogic.Name=${TRIGO_WL_SERVER} \
            -Dbea.home=${BEA_HOME} \
            -Dweblogic.management.username=${TRIGO_WL_USER} \
            -Dweblogic.management.password=${TRIGO_WL_PW} \
            -Dweblogic.ProductionModeEnabled=${STARTMODE} \
            -Djava.security.policy==${WL_HOME}/server/lib/weblogic.policy \
            weblogic.Server
        ;;
    websphere)
        InitEtcDirForAppSvr websphere
        if [ -e ${WAS_HOME}/bin/startServer.sh ]; then
            ${WAS_HOME}/bin/startServer.sh -configFile ${SVC_ETC_DIR}/websphere/server-cfg.xml
        else
            echo "Warning!  \$TRIGO_APPSVR set to websphere, but couldn't find startServer.sh!"
            echo "If you are using WebSphere Advanced Edition, please set \$TRI GO_APPSVR to \"websphereAE\""
        fi
        ;;
    websphereAE)
        InitEtcDirForAppSvr websphere
        ${WAS_HOME}/bin/wscp.sh -p ${TOP}/etc/default/websphere/wscp.properties -f ${ADMIN_DIR}/websphere/start.tcl ${WAS_NODENAME} ${WAS_APPSERVERNAME}
        ;;
    websphere5)
        InitEtcDirForAppSvr websphere
        ${WAS_HOME}/bin/startServer.sh ${WAS_APPSERVERNAME}
        ;;
    *)
        ${ECHO} "$0: Error!: TRIGO_APPSVR set to \"$TRIGO_APPSVR\". Unknown value"
        ;;
esac
