
#!/bin/bash
# Licensed Materials - Property of IBM
# 5724-I68
#
# (C) Copyright IBM Corp. 2000, 2006
#
# US Government Users Restricted Rights - Use, duplication, or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

# 
# # 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

WL_APPSERVERNAME=${_CCD_APPSERVERNAME:=${CCD_WL_SERVER}}
WAS_APPSERVERNAME=${_CCD_APPSERVERNAME:=${WAS_APPSERVERNAME}}

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}\
            ${CCD_APPSVR_JVM_PROFILING_AGENT} \
            -classpath ${CCD_CLASSPATH} \
            -Dtomcat.home=${TOMCAT_HOME} \
            ${CCD_APPSVR_JVM_PROFILING_OPTS}\
	    -Dprofiler_opts=${CCD_APPSVR_PROFILER_NAME}__${CCD_APPSVR_PROFILER_PORT} \
            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}"

        # Start WebLogic server
        echo CLASSPATH="${CLASSPATH}"
        echo
        echo PATH="${PATH}"
        echo

        startWithLogs ${JDK_HOME}/bin/java \
            ${APPSVR_OPTS} \
            ${CCD_APPSVR_JVM_DEBUG_OPTS}\
            -classpath ${CLASSPATH} \
            -Dweblogic.Name=${WL_APPSERVERNAME} \
            -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
        ;;
    weblogic92)
        InitEtcDirForAppSvr weblogic92
        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

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

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

        ADMIN_URL=http://localhost:${WL_ADMIN_PORT}

        # Start WebLogic server
        echo CLASSPATH="${CLASSPATH}"
        echo
        echo PATH="${PATH}"
        echo

        startWithLogs ${JDK_HOME}/bin/java \
            ${APPSVR_OPTS} \
            ${CCD_APPSVR_JVM_DEBUG_OPTS}\
            ${CCD_APPSVR_JVM_PROFILING_AGENT} \
            -classpath ${CLASSPATH} \
            -Dweblogic.Name=${WL_APPSERVERNAME} \
            -Dplatform.home=${WL_HOME} \
            -Dwls.home=${WL_HOME}/server \
            -Dwli.home=${WL_HOME}/integration \
            -Dweblogic.management.discover=false \
            -Dweblogic.management.server=${ADMIN_URL} \
            -Dweblogic.management.username=${CCD_WL_USER} \
            -Dweblogic.management.password=${CCD_WL_PW} \
            -Dweblogic.ProductionModeEnabled=${STARTMODE} \
            -Djava.security.policy==${WL_HOME}/server/lib/weblogic.policy \
	    -Dprofiler_opts=${CCD_APPSVR_PROFILER_NAME}__${CCD_APPSVR_PROFILER_PORT} \
            weblogic.Server
        ;;
    websphere)
        InitEtcDirForAppSvr websphere
        if [ -e ${WAS_HOME}/bin/startServer.sh ]; then
            startWithLogs ${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
        startWithLogs ${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
        if [ -n "$WAS_SECURITY" ]; then
            ${ECHO}
            ${ECHO} "You have indicated that WAS security is enabled.  Please provide the"
            ${ECHO} "following authentication information:"
            ${ECHO} "WAS Username:"
            read -p "> " WAS_USERNAME
            ${ECHO} "WAS Password (will not echo):"
            read -p "> " -s WAS_PASSWORD
            ${ECHO}
            startWithLogs ${WAS_HOME}/bin/startServer.sh ${WAS_APPSERVERNAME} \
                -username $WAS_USERNAME -password $WAS_PASSWORD
        else
            startWithLogs ${WAS_HOME}/bin/startServer.sh ${WAS_APPSERVERNAME}
        fi
        ;;
    websphere6)
        InitEtcDirForAppSvr websphere
        startWithLogs ${WAS_PROFILE_HOME}/bin/startServer.sh ${WAS_APPSERVERNAME}
        ;;
    *)
        ${ECHO} "$0: Error!: CCD_APPSVR set to \"$CCD_APPSVR\". Unknown value"
        ;;
esac
