JAvaはJARパッケージスクリプトJVMパラメータノートを起動する
19457 ワード
JAvaはJARパッケージスクリプトJVMパラメータノートDEMOを起動する
demo open-api-devops-service.sh
/opt/java/jdk1.8.0_131/bin/java
#
-server
#
-Xmx512m
#
-Xms512m
# (Eden + 2*S) ( )
-XX:NewRatio=4
#Eden Survivor
-XX:SurvivorRatio=8
#
-XX:PermSize=48m
#
-XX:MaxPermSize=64m
#
-Xss256k
#JDK5.0 1M, 256K. . , . , , 3000~5000
, , 128k 256k。 , 。( )
threadstacksize , , :"”
-Xss is translated in a VM flag named ThreadStackSize”
-XX:ThreadStackSize=128k
-XX:-ReduceInitialCardMarks
#
-XX:+PrintGCDetails
#
-XX:+PrintGCTimeStamps
#
-XX:+PrintHeapAtGC
-Xloggc:/home/workspace/jvm-log/open-api-global-quartz-GC.log
# System.gc()
-XX:+DisableExplicitGC
# CMS
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
#CMS
-XX:ParallelCMSThreads=4
#CMS
-XX:+CMSParallelRemarkEnabled
# FULL GC , CMS , , , , , 。 。
,
-XX:+UseCMSCompactAtFullCollection
#CMS 50% CMS
-XX:CMSInitiatingOccupancyFraction=50
#CMS , , " ", . GC , .
-XX:CMSFullGCsBeforeCompaction=2
# ,
-XX:+UseCompressedOops
#
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/home/workspace/jvm_dump/open-api-global-quartz-heapDump.hprof
-jar open-api-global-quartz-exec.jar
--eureka.server=http://localhost:8761/eureka
--environment=Staging --dataCenter=Cloud
demo open-api-devops-service.sh
#!/bin/bash
export JAVA_HOME=$JAVA_HOME
echo ${JAVA_HOME}
APP=open-api-devops-service
APP_JAR=${APP}"-exec.jar"
ENV_SPRING_ACTIVE="--spring.profiles.active=dev"
LOG_DIR=$PWD/start-log
JVM_LOG_DIR=$PWD/jvm-log
JVM_DUMP_DIR=$PWD/jvm-dump
command=$1
#
function start(){
#
if [ ! -d "${LOG_DIR}" ];then
mkdir "${LOG_DIR}"
fi
if [ ! -d "${JVM_LOG_DIR}" ];then
mkdir "${JVM_LOG_DIR}"
fi
if [ ! -d "${JVM_DUMP_DIR}" ];then
mkdir "${JVM_DUMP_DIR}"
fi
rm -f $APP.pid
#${JAVA_HOME}/bin/jar uvf $APP_JAR jdbc.properties
nohup ${JAVA_HOME}/bin/java -server -Xmx512m -Xms512m -XX:NewRatio=4 -XX:SurvivorRatio=8 -XX:PermSize=48 -XX:MaxPermSize=64m -Xss256k -XX:ThreadStackSize=128k -XX:-ReduceInitialCardMarks -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -Xloggc:$JVM_LOG_DIR/$APP-GC.log -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:ParallelCMSThreads=4 -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=50 -XX:CMSFullGCsBeforeCompaction=2 -XX:+UseCompressedOops -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$JVM_DUMP_DIR/$APP-heapDump.hprof -jar $APP_JAR $ENV_SPRING_ACTIVE >> /dev/null 2>$APP-error.log &
echo $! > $APP.pid
check
}
#
function stop(){
tpid=`ps -ef | grep $APP_JAR | grep -v grep | grep -v kill | awk '{print $2}'`
if [ ${tpid} ];then
echo "Stop Process"
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef | grep $APP_JAR | grep -v grep | grep -v kill | awk '{print $2}'`
if [ ${tpid} ];then
echo "Stop Process"
kill -15 $tpid
else
echo "Stop SUCCESS"
fi
sleep 5
tpid=`ps -ef | grep $APP_JAR | grep -v grep | grep -v kill | awk '{print $2}'`
if [ ${tpid} ];then
echo "Stop FAILD"
fi
}
#
function check(){
tpid=`ps -ef | grep $APP_JAR | grep -v grep | grep -v kill | awk '{print $2}'`
if [ ${tpid} ]; then
echo "APP is running"
else
echo "APP is Not running"
fi
}
# kill
function forcekill(){
tpid=`ps -ef | grep $APP_JAR | grep -v grep | grep -v kill | awk '{print $2}'`
if [ ${tpid} ];then
echo "Kill Process"
kill -9 $tpid
fi
}
#
function showtpid(){
tpid=`ps -ef | grep $APP_JAR | grep -v grep | grep -v kill | awk '{print $2}'`
if [ ${tpid} ];then
echo 'Process '$APP_JAR' tpid is '$tpid
else
echo 'Process '$APP_JAR' is not running.'
fi
}
#
function showtpid(){
tpid=`ps -ef|grep $APP_JAR|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'process '$APP_JAR' tpid is '$tpid
else
echo 'process '$APP_JAR' is not running.'
fi
}
if [ "${command}" == "start" ]; then
start
elif [ "${command}" == "stop" ]; then
stop
elif [ "${command}" == "check" ]; then
check
elif [ "${command}" == "status" ]; then
check
elif [ "${command}" == "kill" ]; then
forcekill
elif [ "${command}" == "tpid" ];then
showtpid
else
echo "Unknow argument....[start|stop|check|status|kill|tpid]"
fi