shell 管理SpringBoot 生產環境服務 (配置JVM)

java命令的模版:java [-options] -jar jarfile [args...]

先貼一下個人簡單的啓動命令:

java -Xms128m -Xmx256m -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8081,suspend=n 
-jar /data/app/test.jar --spring.profiles.active=dev &

其中:

-Xms128m 設置的是JVM堆最小內存爲128m

-Xmx256m 設置的是JVM堆最大內存爲256m

這裏有個問題是-Xmx指定的內存不包括jvm運行中使用的本地內存,因此若是有NIO等涉及到本地內存的狀況時,該java進程佔用的總內存會超過-Xmx設定的數值

-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8081,suspend=n

設置debug模式,容許tomcat遠程鏈接服務器調試,調試端口可指定,此處爲8081

/data/app/test.jar 指定須要執行的jar包的路徑

--spring.profiles.active=dev 設定SpringBoot運行環境爲dev環境

& 後臺模式執行

http://blog.csdn.net/jiangzeyin_/article/details/74671334html

http://blog.csdn.net/jiangzeyin_/article/details/74679444 
續上兩篇博客,這裏對命令再次調整java

#!/bin/bash
Tag="Application"
MainClass="com.test.Application"
Lib="/testboot/test/lib/"
Log="/testboot/test/run.log"
JVM="-server -Xms128m -Xmx128m -XX:PermSize=32M -XX:MaxNewSize=64m -XX:MaxPermSize=64m -Djava.awt.headless=true -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled"
echo $Tag
RETVAL="0"

# See how we were called.
function start() {
    echo  $Log 
    if [ ! -f $Log ]; then
        touch $Log
    fi
    nohup java $JVM -Dappliction=$Tag -Djava.ext.dirs=$Lib":${JAVA_HOME}/jre/lib/ext" $MainClass > $Log 2>&1 &  
    tailf $Log
}


function stop() {
    pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
    if [ "$pid" != "" ]; then      
        echo -n "boot ( pid $pid) is running" 
        echo 
        echo -n $"Shutting down boot: "
        pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
        if [ "$pid" != "" ]; then
            echo "kill boot process"
            kill -9 "$pid"
        fi
        else 
             echo "boot is stopped" 
        fi

    status
}

function status()
{
    pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
    #echo "$pid"
    if [ "$pid" != "" ]; then
        echo "boot is running,pid is $pid"
    else
        echo "boot is stopped"
    fi
}



function usage()
{
   echo "Usage: $0 {start|stop|restart|status}"
   RETVAL="2"
}

# See how we were called.
RETVAL="0"
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    reload)
        RETVAL="3"
        ;;
    status)
        status
        ;;
    *)
      usage
      ;;
esac

exit $RETVAL

JVM 相關配置說明:spring

java.awt.headless 模式 
http://blog.csdn.net/wodeyuer125/article/details/50502914tomcat

jvm的內存分佈,參數配置 和 GC處理機制 
http://www.javashuo.com/article/p-gylrdkrh-kc.htmlbash

JVM實用參數 CMS收集器 
http://ifeve.com/useful-jvm-flags-part-7-cms-collector/服務器

JVM參數設置、分析 
https://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.htmlapp

相關文章
相關標籤/搜索