1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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 83 84 85 86 87 88 89 90 91 92 93 94 95
| #! /bin/bash
export APPLICATION="eachbot-kbs"
export APPLICATION_JAR=${APPLICATION}.jar
export JAVA="$JAVA_HOME/bin/java"
export BASE_DIR=`cd $(dirname $0); pwd`
export DEFAULT_SEARCH_LOCATIONS="classpath:/,classpath:/config/,file:./,file:./config/"
export CONFIG_DIR=file:${BASE_DIR}/conf/,${DEFAULT_SEARCH_LOCATIONS}
export PID_CMD="ps -ef |grep $APPLICATION_JAR |grep -v grep |awk '{print \$2}'"
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m" JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BASE_DIR}/logs/java_heapdump.hprof" JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages"
JAVA_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p') echo "java version: $JAVA_VERSION"
if [[ "$JAVA_VERSION" -ge "9" ]] ; then JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${BASE_DIR}/logs/gc.log:time,tags:filecount=10,filesize=102400" else JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext" JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M" fi
JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/${APPLICATION_JAR}"
JAVA_OPT="${JAVA_OPT} --server.max-http-header-size=524288"
if [ ! -d "${BASE_DIR}/logs" ]; then mkdir ${BASE_DIR}/logs fi
if [ ! -f "${BASE_DIR}/logs/start.out" ]; then touch "${BASE_DIR}/logs/start.out" fi
NOW=$(date +"%Y-%m-%m %H:%M:%S")
echo "================================================ ${NOW} ================================================"
echo "system info: `uname`"
echo "application name: ${APPLICATION}"
echo "application jar name: ${APPLICATION_JAR}"
echo "application root path: ${BASE_DIR}"
echo "application bin path: ${BASE_DIR}"
echo "application conf path: ${CONFIG_DIR}"
echo "application start logs: ${BASE_DIR}/logs"
echo "application start cmd: $JAVA ${JAVA_OPT} > ${BASE_DIR}/logs/start.out 2>&1 &"
PID=$(eval $PID_CMD) if [[ -n $PID ]]; then echo "$APPLICATION is already running,PID is $PID" else nohup $JAVA ${JAVA_OPT} > /dev/null 2>&1 & PID=$(eval $PID_CMD) if [[ -n $PID ]]; then echo "Start $APPLICATION successfully, PID is $PID, you can check the ${BASE_DIR}/logs/start.out" else echo "Failed to start $APPLICATION !!!" fi fi
|