Dubbox 官方dubbo启动脚本 (带JVM参数,支持远程调试)

为什么80%的码农都做不了架构师?>>>   hot3.png

我项目结构如图:

etc :配置文件目录 (都是properties和xml)

lib:依赖包和源码包(都是.jar)

sbin:启动脚本目录(都是.sh)

Dubbox 官方dubbo启动脚本 (带JVM参数,支持远程调试)_第1张图片 

 我在项目中使用脚本如下:

 

#!/bin/bash
#author: dy
PROJECT_MAIN=com.trc.funds.balance.dubbo.FundsBalanceService
BASE_DIR=$(cd `dirname $0`;cd ..;pwd)
CONF_DIR=$BASE_DIR/etc
STDOUT_FILE=$BASE_DIR/stdout.log

SERVER_NAME=`sed '/rpc.dubbo.application.name/!d;s/.*=//' etc/config/dubbo-provider.properties | tr -d '\r'`
SERVER_PORT=`sed '/rpc.dubbo.protocol.port/!d;s/.*=//' etc/config/dubbo-provider.properties | tr -d '\r'`
SERVER_PROTOCOL=`sed '/rpc.dubbo.protocol.name/!d;s/.*=//' etc/config/dubbo-provider.properties | tr -d '\r'`


if [ -z "$SERVER_NAME" ]; then
    SERVER_NAME=`hostname`
fi

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

if [ -n "$SERVER_PORT" ]; then
    SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`
    if [ $SERVER_PORT_COUNT -gt 0 ]; then
        echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"
        exit 1
    fi
fi

LIB_DIR=$BASE_DIR/lib
LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr "\n" ":"`

JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
JAVA_DEBUG_OPTS=""
if [ "$1" = "debug" ]; then
    JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "
fi
JAVA_JMX_OPTS=""
if [ "$1" = "jmx" ]; then
    JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "
fi

JAVA_MEM_OPTS=""
BITS=`java -version 2>&1 | grep -i 64-bit`
if [ -n "$BITS" ]; then
    JAVA_MEM_OPTS=" -server -Xmx2g -Xms2g -Xmn1g -XX:PermSize=256m -Xss256k -XX:+DisableExplicitGC
    -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
else
    JAVA_MEM_OPTS=" -server -Xms2g -Xmx2g -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
fi

echo -e "Starting the $SERVER_NAME ...\c"
nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS $PROJECT_MAIN > $STDOUT_FILE 2>&1 &

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

 

转载于:https://my.oschina.net/dyyweb/blog/783701

你可能感兴趣的:(Dubbox 官方dubbo启动脚本 (带JVM参数,支持远程调试))