#!/bin/bash

# Copyright (c) 2000, 2004 IBM Corp. - All Rights Reserved.
# IBM makes no representations or warranties about the suitability of
# this program, either express or implied, including but not limited to
# the implied warranties of merchantability, fitness for a particular
# purpose, or non-infringement. 
  
# 
# # Copyright (c) 2000, 2004 IBM Corp. - All Rights Reserved.
# # IBM makes no representations or warranties about the suitability of
# # this program, either express or implied, including but not limited to
# # the implied warranties of merchantability, fitness for a particular
# # purpose, or non-infringement. 
# 
#


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

if [ ! "${_CCD_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 "${CCD_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="-DCCD_HOSTNAME=${SHORT_HOSTNAME} -DCCD_APPSVR_PORT=${_CCD_CONF_APPSVR_PORT} -DCCD_TOMCAT_AJP12=${_CCD_CONF_TOMCAT_AJP12} -DCCD_TOMCAT_AJP13=${_CCD_CONF_TOMCAT_AJP13}"
        APPSVR_OPTS="${APPSVR_OPTS} ${EXTRA_APPSVR_VARS}"

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

    weblogic81)
        InitEtcDirForAppSvr weblogic81
        cd ${WL_HOME}/server/bin
        export CLASSPATH=
        # Call commEnv here AFTER setting the java_vendor to get common environmental settings.
        . ${WL_HOME}/common/bin/commEnv.sh

        #export CLASSPATH=${CCD_CLASSPATH}${PATH_SEPARATOR}${CLASSPATH}
        CLASSPATH="${CCD_CLASSPATH}${PATH_SEPARATOR}${WEBLOGIC_CLASSPATH}:${POINTBASE_CLASSPATH}:${JAVA_HOME}/jre/lib/rt.jar:${WL_HOME}/server/lib/webservices.jar:${CLASSPATH}"
        cd ${CCD_WL_DOMAIN_DIR}

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

        startWithLogs ${JDK_HOME}/bin/java \
            ${APPSVR_OPTS} \
            ${CCD_APPSVR_JVM_DEBUG_OPTS}\
            -classpath ${CLASSPATH} \
            -Dweblogic.Name=${CCD_WL_SERVER} \
            -Dbea.home=${BEA_HOME} \
            -Dweblogic.management.username=${CCD_WL_USER} \
            -Dweblogic.management.password=${CCD_WL_PW} \
            -Dweblogic.ProductionModeEnabled=${STARTMODE} \
            -Djava.security.policy==${WL_HOME}/server/lib/weblogic.policy \
            weblogic.Server
        ;;
    weblogic700)
        InitEtcDirForAppSvr weblogic700
        cd ${WL_HOME}/server/bin
        export CLASSPATH=
        . ./setWLSEnv.sh
        export CLASSPATH=${CCD_CLASSPATH}${PATH_SEPARATOR}${CLASSPATH}
        cd ${CCD_WL_DOMAIN_DIR}

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

        startWithLogs ${JDK_HOME}/bin/java \
            ${APPSVR_OPTS} \
            ${CCD_APPSVR_JVM_DEBUG_OPTS}\
            -classpath ${CLASSPATH} \
            -Dweblogic.Name=${CCD_WL_SERVER} \
            -Dbea.home=${BEA_HOME} \
            -Dweblogic.management.username=${CCD_WL_USER} \
            -Dweblogic.management.password=${CCD_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!  \$CCD_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!: CCD_APPSVR set to \"$CCD_APPSVR\". Unknown value"
        ;;
esac
