#!/bin/sh

#######################################
#        JBoss Default Setting        #
#######################################

export DATE=`date +%Y%m%d%H%M%S`
export LANG=ko_KR.utf8

export JAVA_HOME=/usr/lib/jvm/jre-1.8.0
export JBOSS_HOME=/WAS/apm/jboss/jboss
export DOMAIN_BASE=/WAS/apm/jboss/servers

export SERVER_NAME=watch11
export SERVER_HOME=$DOMAIN_BASE/$SERVER_NAME

#######################################
#          Configration File          #
#######################################

export CONFIG_FILE=standalone.xml

export HOST_NAME=Rsmscouter2
export NODE_NAME=$SERVER_NAME
export PORT_OFFSET=100

export JBOSS_USER=jboss

#######################################
#            Bind Address             #
#######################################
##### JBoss Directory Setup

export BIND_ADDR=0.0.0.0
export MGMT_ADDR=10.227.59.21

export CONTROLLER_IP=$MGMT_ADDR
let CONTROLLER_PORT=9990+$PORT_OFFSET
export CONTROLLER_PORT

#######################################
#            port usage               #
#######################################

#=============================
#ex) export HTTP_CUSTOM_PORT=8080
#ex) export AJP_CUSTOM_PORT=8309
#=============================

export HTTP_DEFAULT_PORT=8080
export AJP_DEFAULT_PORT=8009

if [ "x$HTTP_CUSTOM_PORT" = "x" ]; then
    HTTP_PORT=$HTTP_DEFAULT_PORT
    AJP_PORT=$AJP_DEFAULT_PORT

    let HTTP_FINAL_PORT=$HTTP_PORT+$PORT_OFFSET
    let AJP_FINAL_PORT=$AJP_PORT+$PORT_OFFSET

    export HTTP_FINAL_PORT
    export AJP_FINAL_PORT

else

    if [ "x$AJP_CUSTOM_PORT" = "x" ]; then

        AJP_PORT=$AJP_DEFAULT_PORT
        
        let HTTP_PORT=$HTTP_CUSTOM_PORT-$PORT_OFFSET
        let AJP_FINAL_PORT=$AJP_PORT+$PORT_OFFSET

        export HTTP_FINAL_PORT=$HTTP_CUSTOM_PORT
        export AJP_FINAL_PORT

    else
        let HTTP_PORT=$HTTP_CUSTOM_PORT-$PORT_OFFSET
        let AJP_PORT=$AJP_CUSTOM_PORT-$PORT_OFFSET

        export HTTP_FINAL_PORT=$HTTP_CUSTOM_PORT
        export AJP_FINAL_PORT=$AJP_CUSTOM_PORT
    fi
fi

export HTTP_PORT
export AJP_PORT

export JGROUP_TCP_PORT=7600
let JGROUP_TCP_PORT=7600+$PORT_OFFSET
export JGROUP_TCP_PORT

export JMXREMOTE_TCP_PORT=5999
let JMXREMOTE_TCP_PORT=5999+$PORT_OFFSET
export JMXREMOTE_TCP_PORT

#export JBOSS_JGROUPS_STACK=udp
#export JBOSS_JGROUPS_TCPPING_INITIAL_HOSTS=10.227.59.21[$JGROUP_TCP_PORT],10.227.59.21[$JGROUP_TCP_PORT]
#export JBOSS_JGROUPS_TCPPING_NUM_INITIAL_MEMBERS=2

export LAUNCH_JBOSS_IN_BACKGROUND=true


######################################################
##### Logging Directory Setup
######################################################

export LOG_HOME=${SERVER_HOME}/logs
export LOG_DIR=${LOG_HOME}/log
export GC_LOG_DIR=${LOG_HOME}/gclog
export HEAP_DUMP_DIR=${LOG_HOME}/heaplog
#export LOG_LEVEL=INFO

##### JBoss System module and User module directory #####
export JBOSS_MODULEPATH=$JBOSS_HOME/modules:$JBOSS_HOME/modules.ext

# JVM Options : Server
export JAVA_OPTS="-server $JAVA_OPTS"

# JVM Options : Memory

    JAVA_OPTS="$JAVA_OPTS -Xms1024m -Xmx1024m"
    JAVA_OPTS="$JAVA_OPTS -XX:MetaspaceSize=256m"
    JAVA_OPTS="$JAVA_OPTS -XX:MaxMetaspaceSize=512m"
    JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC"

    JAVA_OPTS="$JAVA_OPTS -verbose:gc"
    JAVA_OPTS="$JAVA_OPTS -Xloggc:${GC_LOG_DIR}/gc.log.$DATE"
    JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails"
    JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDateStamps"
    JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps"

    JAVA_OPTS="$JAVA_OPTS -XX:+UseGCLogFileRotation"
    JAVA_OPTS="$JAVA_OPTS -XX:NumberOfGCLogFiles=5"
    JAVA_OPTS="$JAVA_OPTS -XX:GCLogFileSize=2048K"

    JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
    JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=${LOG_DIR}/${SERVER_NAME}.$DATE.hprof"

    JAVA_OPTS="$JAVA_OPTS -XX:+PrintAdaptiveSizePolicy"
    JAVA_OPTS="$JAVA_OPTS -XX:+UseLargePagesInMetaspace"
    JAVA_OPTS="$JAVA_OPTS -XX:+ExplicitGCInvokesConcurrent"
    JAVA_OPTS="$JAVA_OPTS -XX:+DisableExplicitGC"

    JAVA_OPTS="$JAVA_OPTS -XX:ReservedCodeCacheSize=512m"
    JAVA_OPTS="$JAVA_OPTS -XX:-UseCodeCacheFlushing"

    JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
    JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
    JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/urandom"

    JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.resolver.warning=true"
    JAVA_OPTS="$JAVA_OPTS -Dsun.rmi.dgc.client.gcInterval=3600000 "
    JAVA_OPTS="$JAVA_OPTS -Dsun.rmi.dgc.server.gcInterval=3600000"
    JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
#    JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=org.jboss.byteman,scouter,org.jboss.logmanager"
    JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=org.jboss.byteman,scouter"

# Linux Large Page Setting
#export JAVA_OPTS=" $JAVA_OPTS  -XX:+UseLargePages "

#for darwin
export JBOSS_BASE_DIR="$DOMAIN_BASE/$SERVER_HOME"

export JAVA_OPTS="$JAVA_OPTS -Djboss.server.base.dir=$DOMAIN_BASE/$SERVER_NAME"
export JAVA_OPTS="$JAVA_OPTS -Djboss.server.log.dir=$LOG_DIR"
export JAVA_OPTS="$JAVA_OPTS -Djboss.socket.binding.port-offset=$PORT_OFFSET"

export JAVA_OPTS="$JAVA_OPTS -Djboss.node.name=$NODE_NAME"
export JAVA_OPTS="$JAVA_OPTS -Djboss.log.name=$NODE_NAME.log"
export JAVA_OPTS="$JAVA_OPTS -Djboss.server.log.dir=$LOG_DIR"
export JAVA_OPTS="$JAVA_OPTS -Djboss.server.base.dir=$DOMAIN_BASE/$SERVER_NAME"
export JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address=$BIND_ADDR"
export JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address.management=$MGMT_ADDR"
export JAVA_OPTS="$JAVA_OPTS -Djboss.socket.binding.port-offset=$PORT_OFFSET"

export JAVA_OPTS="$JAVA_OPTS -Djboss.default.multicast.address=$MULTICAST_ADDR"
export JAVA_OPTS="$JAVA_OPTS -Djboss.messaging.group.address=$JMS_MULTICAST_ADDR"
export JAVA_OPTS="$JAVA_OPTS -Djboss.modcluster.multicast.address=$MODCLUSTER_MULTICAST_ADDR"

#export JAVA_OPTS=" $JAVA_OPTS -Djboss.mod_cluster.excludedContexts=admin-console,invoker,jbossws,jmx-console,juddi,web-console,images,test"

export JAVA_OPTS="$JAVA_OPTS -Djboss.http.port=$HTTP_PORT"
export JAVA_OPTS="$JAVA_OPTS -Djboss.http.final.port=$HTTP_FINAL_PORT"
export JAVA_OPTS="$JAVA_OPTS -Djboss.ajp.port=$AJP_PORT"
export JAVA_OPTS="$JAVA_OPTS -Djboss.ajp.final.port=$AJP_FINAL_PORT"

#export JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:/WAS/jboss/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-1.5.4.Final-redhat-1.jar"

#export JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:/home/asmanager/jboss/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-1.5.4.Final-redhat-1.jar"
#export JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.jboss.logmanager.LogManager"

#export JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote"
#export JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=$JMXREMOTE_TCP_PORT"
#export JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
#export JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"

#############
#  WatchAPM Otps ##
#############

export JAVA_OPTS="$JAVA_OPTS -Dserver.mode=prd"
export JAVA_OPTS="$JAVA_OPTS -Ddb.connect.type=jndi"
export JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=classpath:classes/logback.xml"


# Use log4j in application
export JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"

# SecureRandom Bug
# http://wiki.apache.org/tomcat/HowTo/FasterStartUp
export JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"

#################################################
# Reno Samsung Motors SAP LD_LIBRARY_PATH                                                                                       
#################################################
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JBOSS_HOME/lib
#export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/WAS/users/apps/SAPLIB"
#export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/WAS/users/support/nss/FirstData"

#export LIB_PATH="$LIB_PATH:/WAS/users/apps/SAPLIB"
#export LIB_PATH="$LIB_PATH:/WAS/users/support/nss/FirstData"

#################################################
## Application Performance Monitoring - Scouter #
#################################################
#export JAVA_OPTS="$JAVA_OPTS -Dscouter.config=/WAS/scouter/agent/conf/jdk18-svr-11.conf"
#export JAVA_OPTS="$JAVA_OPTS -javaagent:/WAS/scouter/agent/java/scouter.agent.jar"

echo "================================================"
echo "JAVA_HOME=$JAVA_HOME"
echo "JBOSS_HOME=$JBOSS_HOME"
echo "DOMAIN_BASE=$DOMAIN_BASE"
echo "SERVER_NAME=$SERVER_NAME"
echo "CONFIG_FILE=$CONFIG_FILE"
echo "BIND_ADDR=$BIND_ADDR"
echo "PORT_OFFSET=$PORT_OFFSET"
echo "MULTICAST_ADDR=$MULTICAST_ADDR"
echo "CONTROLLER=$CONTROLLER_IP:$CONTROLLER_PORT"
echo "HTTP_FINAL_PORT=$HTTP_FINAL_PORT"
echo "AJP_FINAL_PORT=$AJP_FINAL_PORT"
echo "================================================"

