startup.sh 3.8 KB
Newer Older
Y
Yiming Liu 已提交
1 2
#!/bin/bash
SERVICE_NAME=apollo-portal
3
## Adjust log dir if necessary
J
Jason Song 已提交
4
LOG_DIR=/opt/logs/100003173
5
## Adjust server port if necessary
J
Jason Song 已提交
6
SERVER_PORT=8080
Y
Yiming Liu 已提交
7

8
## Adjust memory settings if necessary
N
nobodyiam 已提交
9
#export JAVA_OPTS="-Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=1536m -XX:MaxNewSize=1536m -XX:SurvivorRatio=8"
10 11 12

## Only uncomment the following when you are using server jvm
#export JAVA_OPTS="$JAVA_OPTS -server -XX:-ReduceInitialCardMarks"
Y
Yiming Liu 已提交
13

J
Jason Song 已提交
14
########### The following is the same for configservice, adminservice, portal ###########
15
export JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -XX:+UseCMSInitiatingOccupancyOnly -XX:+ScavengeBeforeFullGC -XX:+UseCMSCompactAtFullCollection -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=9 -XX:CMSInitiatingOccupancyFraction=60 -XX:+CMSClassUnloadingEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSPermGenSweepingEnabled -XX:CMSInitiatingPermOccupancyFraction=70 -XX:+ExplicitGCInvokesConcurrent -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom"
16
export JAVA_OPTS="$JAVA_OPTS -Dserver.port=$SERVER_PORT -Dlogging.file=$LOG_DIR/$SERVICE_NAME.log -Xloggc:$LOG_DIR/heap_trace.txt -XX:HeapDumpPath=$LOG_DIR/HeapDumpOnOutOfMemoryError/"
J
Jason Song 已提交
17 18

PATH_TO_JAR=$SERVICE_NAME".jar"
19
SERVER_URL="http://localhost:$SERVER_PORT"
Y
Yiming Liu 已提交
20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
function checkPidAlive {
    for i in `ls -t $SERVICE_NAME*.pid 2>/dev/null`
    do
        read pid < $i

        result=$(ps -p "$pid")
        if [ "$?" -eq 0 ]; then
            return 0
        else
            printf "\npid - $pid just quit unexpectedly, please check logs under $LOG_DIR and /tmp for more information!\n"
            exit 1;
        fi
    done

    printf "\nNo pid file found, startup may failed. Please check logs under $LOG_DIR and /tmp for more information!\n"
    exit 1;
}

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
if [ "$(uname)" == "Darwin" ]; then
    windows="0"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
    windows="0"
elif [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
    windows="1"
else
    windows="0"
fi

# for Windows
if [ "$windows" == "1" ] && [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
    tmp_java_home=`cygpath -sw "$JAVA_HOME"`
    export JAVA_HOME=`cygpath -u $tmp_java_home`
    echo "Windows new JAVA_HOME is: $JAVA_HOME"
J
Jason Song 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
fi

cd `dirname $0`/..

for i in `ls $SERVICE_NAME-*.jar 2>/dev/null`
do
    if [[ ! $i == *"-sources.jar" ]]
    then
        PATH_TO_JAR=$i
        break
    fi
done

if [[ ! -f PATH_TO_JAR && -d current ]]; then
    cd current
    for i in `ls $SERVICE_NAME-*.jar 2>/dev/null`
    do
        if [[ ! $i == *"-sources.jar" ]]
        then
            PATH_TO_JAR=$i
            break
        fi
    done
fi

if [[ -f $SERVICE_NAME".jar" ]]; then
  rm -rf $SERVICE_NAME".jar"
fi

N
nobodyiam 已提交
83
printf "$(date) ==== Starting ==== \n"
J
Jason Song 已提交
84

J
Jason Song 已提交
85 86 87 88 89 90 91 92
ln $PATH_TO_JAR $SERVICE_NAME".jar"
chmod a+x $SERVICE_NAME".jar"
./$SERVICE_NAME".jar" start

rc=$?;

if [[ $rc != 0 ]];
then
N
nobodyiam 已提交
93
    echo "$(date) Failed to start $SERVICE_NAME.jar, return code: $rc"
J
Jason Song 已提交
94 95 96 97
    exit $rc;
fi

declare -i counter=0
98
declare -i max_counter=48 # 48*5=240s
J
Jason Song 已提交
99 100
declare -i total_time=0

N
nobodyiam 已提交
101
printf "Waiting for server startup"
102
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "Coyote")" != "" ]];
J
Jason Song 已提交
103
do
N
nobodyiam 已提交
104
    printf "."
J
Jason Song 已提交
105 106
    counter+=1
    sleep 5
107 108

    checkPidAlive
J
Jason Song 已提交
109 110 111 112 113 114
done

total_time=counter*5

if [[ (( counter -ge max_counter )) ]];
then
N
nobodyiam 已提交
115
    printf "\n$(date) Server failed to start in $total_time seconds!\n"
J
Jason Song 已提交
116 117 118
    exit 1;
fi

N
nobodyiam 已提交
119
printf "\n$(date) Server started in $total_time seconds!\n"
J
Jason Song 已提交
120 121

exit 0;