env.sh 5.62 KB
#!/bin/bash
################################################################
#@Authro Lijian
#@Date 2007-05-24
################################################################

BASE_BIN_DIR=`dirname $0`
. $BASE_BIN_DIR/functions.sh

export JAVA_HOME=${yoho.env.javahome}
export WEB_APP_HOME=${ufo.gateway.env.webapphome}
export SERVER_PORT=${ufo.gateway.env.serverport}
export PRODUCTION_MODE="${yoho.env.productmode}"
export SERVER_HOME=${yoho.env.serverhome}
export SERVER_TYPE=${yoho.env.servertype}
export SERVER_NAMESPACE=${ufo.gateway.env.namespace}
export JACOCO_HOME=/Data/local/jacoco

#if("${yoho.env.servertype}"=="jboss")
    export SERVER_BASE_DIR=" -Djboss.server.base.dir=${ufo.gateway.env.webapphome}/.jboss/default "
#end

#if("${yoho.env.servertype}"=="tomcat")
    export SERVER_BASE_DIR=" -Dcatalina.base=${ufo.gateway.env.webapphome}/.tomcat "
#end

export NAMING_PORT=`expr 9000 + $SERVER_PORT`
export HTTP_SERVER_PORT=`expr 8080 + $SERVER_PORT`
export DEBUG_PORT=`expr 8800 + $SERVER_PORT`
 
export CHECK_SERVER_STARTUP_URL="http://127.0.0.1:$HTTP_SERVER_PORT/$SERVER_NAMESPACE/common/ok.jsp"
export STARTUP_SUCCESS_MSG="Server Online Resources ok"
export JAVA_OPTS=" -XX:-OmitStackTraceInFastThrow -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
export JAVA_DEBUG_OPT=" -server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=n "

#jmx
export JMX_PORT=`expr 9600 + $SERVER_PORT`
export LOCAL_IP=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"|awk 'NR==1 {print}'`
export CATALINA_OPTS="$CATALINA_OPTS -Djava.rmi.server.hostname=$LOCAL_IP -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

if [ -d $JACOCO_HOME ]; then
    export CATALINA_OPTS="-javaagent:$JACOCO_HOME/lib/jacocoagent.jar=includes=com.yoho.*:com.yohobuy.*,output=tcpserver,port=8891,address=* $CATALINA_OPTS"
fi

if [ ! -e $JAVA_HOME ]; then
    failed "********************************************************************"
    failed "**Error: JAVA_HOME $JAVA_HOME not exist"
    failed "********************************************************************"    
    exit 1
fi

if [ ! -e $SERVER_HOME ]; then
    failed "********************************************************************"
    failed "**Error: SERVER_HOME $SERVER_HOME not exist."
    failed "********************************************************************"
    exit 1
fi
#========end enviroment var define


################################################################
if [ $PRODUCTION_MODE = "PRODUCT" ]; then
    #after the environment of online is all 64-bit,the below if and else judgement can be delete
    str=`file $JAVA_HOME/bin/java | grep 64-bit`
    if [ -n "$str" ]; then
        let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`
        if [ $memTotal -gt 10000 ];then
            #JAVA_MEM_OPTS=" -server -XX:+UseG1GC -Xmx3G -XX:MaxGCPauseMillis=50 -Xloggc:/Data/logs/gateway/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps "
            JAVA_MEM_OPTS=" -server -XX:+UseG1GC -Xmx2G -XX:MaxGCPauseMillis=10 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=15 -XX:G1MaxNewSizePercent=30 -XX:SurvivorRatio=6 -XX:InitiatingHeapOccupancyPercent=30 -XX:G1MixedGCLiveThresholdPercent=50 -XX:G1HeapWastePercent=5 -XX:+PrintGCDetails -Xloggc:$yoho.logs.basedir/gateway/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$yoho.logs.basedir/gateway/heapdump.hprof "
        else
            #JAVA_MEM_OPTS=" -server -XX:+UseG1GC -Xmx2G -XX:MaxGCPauseMillis=50 -Xloggc:/Data/logs/gateway/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps "
            JAVA_MEM_OPTS=" -server -XX:+UseG1GC -Xmx2G -XX:MaxGCPauseMillis=10 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=15 -XX:G1MaxNewSizePercent=30 -XX:SurvivorRatio=6 -XX:InitiatingHeapOccupancyPercent=30 -XX:G1MixedGCLiveThresholdPercent=50 -XX:G1HeapWastePercent=5 -XX:+PrintGCDetails -Xloggc:$yoho.logs.basedir/gateway/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$yoho.logs.basedir/gateway/heapdump.hprof "
        fi
    else
        JAVA_MEM_OPTS=" -server -XX:+UseG1GC -Xmx3G -XX:MaxGCPauseMillis=50 -Xloggc:/Data/logs/gateway/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps "
    fi
        
    JAVA_OPTS=" $JAVA_OPTS $JAVA_MEM_OPTS "
     
elif [ $PRODUCTION_MODE = "TEST" ]; then
    JAVA_MEM_OPTS=" -server -Xmx1024M -Xms1024M -Xmn512M -XX:MetaspaceSize=200M -XX:+PrintTenuringDistribution -XX:MaxMetaspaceSize=200M -Xss256K -XX:+DisableExplicitGC -XX:SurvivorRatio=3 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+CMSClassUnloadingEnabled -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:-OmitStackTraceInFastThrow -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -Xloggc:$yoho.logs.basedir/gateway/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$WEB_APP_HOME/logs/heapdump.hprof "
	JAVA_OPTS=" $JAVA_OPTS $JAVA_MEM_OPTS "
elif [ $PRODUCTION_MODE = "DEV" ]; then
    #we shuold reduce resource usage on developing mode
    JAVA_MEM_OPTS=" -server -Xms256m -Xmx256m  "
    JAVA_OPTS=" $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPT "
else
    failed "********************************************************************"
    failed "**Error: \$PRODUCTION_MODE should be only: run, test, dev"
    failed "********************************************************************"    
    exit 1
fi


JAVA_OPTS=" $JAVA_OPTS $SERVER_BASE_DIR "