linux常用JAVA应该启动脚本

#!/bin/sh

SERVER_NAME=blade-country-kafka.jar
JAVA_HOME="/usr/local/jdk/bin"

cd `dirname $0`
#cd ..
SERVER_DIR=`pwd`
LOG_DIR=$SERVER_DIR/logs

echo "server dir is $SERVER_DIR"

JAVA_OPTS="-server"
#memory
JAVA_OPTS="$JAVA_OPTS -Xmx1g -Xms1g -Xss256k -XX:MaxDirectMemorySize=1G"
#gc
JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=40 -XX:+PrintGCDateStamps -Xloggc:$LOG_DIR/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$LOG_DIR/java.hprof -XX:+DisableExplicitGC -XX:-OmitStackTraceInFastThrow -XX:+PrintCommandLineFlags -XX:+UnlockCommercialFeatures -XX:+FlightRecorder"
#param
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Djava.util.Arrays.useLegacyMergeSort=true -Dfile.encoding=UTF-8"

if [ ! -e "$SERVER_DIR/$SERVER_NAME" ]; then
    echo "ERROR: the $SERVER_NAME does not exists!"
    exit 1
fi

if [ ! -d "$LOG_DIR" ]; then
    echo 'log dir is not exists'
    mkdir -p "$LOG_DIR"
fi

PIDS=`ps -f | grep java | grep "${SERVER_NAME}" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
    echo "ERROR: The ${SERVER_NAME} already started!"
    echo "PID: $PIDS"
    exit 1
fi

echo -e "Starting the ${SERVER_NAME} ...\c"

echo "JAVA_OPTS=$JAVA_OPTS"

STDOUT_FILE=$LOG_DIR/stdout.log

nohup $JAVA_HOME/java $JAVA_OPTS -jar $SERVER_DIR/$SERVER_NAME --logging.config=$SERVER_DIR/config/logback-spring.xml > $STDOUT_FILE 2>&1 &

COUNT=0
while [ $COUNT -lt 1 ]; do
    sleep 1
    COUNT=`ps -f | grep java | grep "$SERVER_DIR/$SERVER_NAME" | awk '{print $2}' | wc -l`
    if [ $COUNT -gt 0 ]; then
        break
    fi
done

echo "start ${SERVER_NAME} OK!"
PIDS=`ps -f | grep java | grep "$SERVER_DIR/$SERVER_NAME" | awk '{print $2}'`
echo "PID: $PIDS"
echo "STDOUT: $STDOUT_FILE"


 

你可能感兴趣的:(java,后端)