seata-namingserver-setup.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/bin/bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. # Setup JVM parameters for seata server
  19. # resolve links - $0 may be a softlink
  20. PRG="$0"
  21. while [ -h "$PRG" ]; do
  22. ls=`ls -ld "$PRG"`
  23. link=`expr "$ls" : '.*-> \(.*\)$'`
  24. if expr "$link" : '/.*' > /dev/null; then
  25. PRG="$link"
  26. else
  27. PRG=`dirname "$PRG"`/"$link"
  28. fi
  29. done
  30. PRGDIR=`dirname "$PRG"`
  31. BASEDIR=`cd "$PRGDIR/.." >/dev/null; pwd`
  32. BASEDIR=${BASEDIR//"//"/"/"}
  33. # Reset the REPO variable. If you need to influence this use the environment setup file.
  34. REPO=
  35. # OS specific support. $var _must_ be set to either true or false.
  36. cygwin=false;
  37. darwin=false;
  38. case "`uname`" in
  39. CYGWIN*) cygwin=true ;;
  40. Darwin*) darwin=true
  41. if [ -z "$JAVA_VERSION" ] ; then
  42. JAVA_VERSION="CurrentJDK"
  43. else
  44. echo "Using Java version: $JAVA_VERSION"
  45. fi
  46. if [ -z "$JAVA_HOME" ]; then
  47. if [ -x "/usr/libexec/java_home" ]; then
  48. JAVA_HOME=`/usr/libexec/java_home`
  49. else
  50. JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
  51. fi
  52. fi
  53. ;;
  54. esac
  55. if [ -z "$JAVA_HOME" ] ; then
  56. if [ -r /etc/gentoo-release ] ; then
  57. JAVA_HOME=`java-config --jre-home`
  58. fi
  59. fi
  60. # For Cygwin, ensure paths are in UNIX format before anything is touched
  61. if $cygwin ; then
  62. [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  63. [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  64. fi
  65. # If a specific java binary isn't specified search for the standard 'java' binary
  66. if [ -z "$JAVACMD" ] ; then
  67. if [ -n "$JAVA_HOME" ] ; then
  68. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  69. # IBM's JDK on AIX uses strange locations for the executables
  70. JAVACMD="$JAVA_HOME/jre/sh/java"
  71. else
  72. JAVACMD="$JAVA_HOME/bin/java"
  73. fi
  74. else
  75. JAVACMD=`which java`
  76. fi
  77. fi
  78. if [ ! -x "$JAVACMD" ] ; then
  79. echo "Error: JAVA_HOME is not defined correctly." 1>&2
  80. echo " We cannot execute $JAVACMD" 1>&2
  81. exit 1
  82. fi
  83. if [ -z "$REPO" ]
  84. then
  85. REPO="$BASEDIR"/lib
  86. fi
  87. CLASSPATH="$BASEDIR"/conf:"$REPO"/*
  88. ENDORSED_DIR=
  89. if [ -n "$ENDORSED_DIR" ] ; then
  90. CLASSPATH=$BASEDIR/$ENDORSED_DIR/*:$CLASSPATH
  91. fi
  92. if [ -n "$CLASSPATH_PREFIX" ] ; then
  93. CLASSPATH=$CLASSPATH_PREFIX:$CLASSPATH
  94. fi
  95. # For Cygwin, switch paths to Windows format before running java
  96. if $cygwin; then
  97. [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  98. [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  99. [ -n "$HOME" ] && HOME=`cygpath --path --windows "$HOME"`
  100. [ -n "$BASEDIR" ] && BASEDIR=`cygpath --path --windows "$BASEDIR"`
  101. [ -n "$REPO" ] && REPO=`cygpath --path --windows "$REPO"`
  102. fi
  103. JVM_XMX=$JVM_XMX
  104. JVM_XMS=$JVM_XMS
  105. JVM_XSS=$JVM_XSS
  106. JVM_MetaspaceSize=$JVM_MetaspaceSize
  107. JVM_MaxMetaspaceSize=$JVM_MaxMetaspaceSize
  108. JVM_MaxDirectMemorySize=$JVM_MaxDirectMemorySize
  109. LOADER_PATH=$LOADER_PATH
  110. LOG_HOME=$LOG_HOME
  111. if [ -z "$LOG_HOME" ]; then
  112. LOG_HOME="$HOME/logs/seata"
  113. mkdir -p $LOG_HOME
  114. fi
  115. JAVA_OPT="${JAVA_OPT} -Dlog.home=${LOG_HOME} -server -Dloader.path=${LOADER_PATH:="$BASEDIR/lib"} -Xmx${JVM_XMX:="2048m"} -Xms${JVM_XMS:="2048m"} -Xss${JVM_XSS:="640k"} -XX:SurvivorRatio=10 -XX:MetaspaceSize=${JVM_MetaspaceSize:="128m"} -XX:MaxMetaspaceSize=${JVM_MaxMetaspaceSize:="256m"} -XX:MaxDirectMemorySize=${JVM_MaxDirectMemorySize:=1024m} -XX:-OmitStackTraceInFastThrow -XX:-UseAdaptiveSizePolicy"
  116. JAVA_OPT="${JAVA_OPT} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${LOG_HOME}/java_heapdump.hprof -XX:+DisableExplicitGC"
  117. JAVA_MAJOR_VERSION=$($JAVACMD -version 2>&1 | sed '1!d' | sed -e 's/"//g' | awk '{print $3}' | awk -F '.' '{print $1}')
  118. if [[ "$JAVA_MAJOR_VERSION" -eq "1" ]] ; then
  119. JAVA_MAJOR_VERSION=$($JAVACMD -version 2>&1 | sed '1!d' | sed -e 's/"//g' | awk '{print $3}' | awk -F '.' '{print $2}')
  120. fi
  121. if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] ; then
  122. JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${LOG_HOME}/seata_gc.log:time,tags:filecount=10,filesize=10M"
  123. else
  124. JAVA_OPT="${JAVA_OPT} -Xloggc:${LOG_HOME}/seata_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC"
  125. fi
  126. JAVA_OPT="${JAVA_OPT} -Dio.netty.leakDetectionLevel=advanced"
  127. JAVA_OPT="${JAVA_OPT} -Dapp.name=seata-namingserver -Dapp.pid=${$} -Dapp.home=${BASEDIR} -Dbasedir=${BASEDIR}"
  128. if [ "$JMX_ENABLE" = "true" ]; then
  129. JMX_PORT=$JMX_PORT
  130. JMX_OPTS=$JMX_OPTS
  131. if [ -z "$JMX_OPTS" ]; then
  132. JMX_OPTS=" -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false "
  133. fi
  134. if [ -z "$JMX_PORT" ]; then
  135. JMX_OPTS=" $JMX_OPTS -Dcom.sun.management.jmxremote.port=${JMX_PORT:="10055"} -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT:="10055"} "
  136. fi
  137. echo "JMX enabled"
  138. else
  139. echo "JMX disabled"
  140. fi
  141. JAVA_OPT="${JAVA_OPT} ${JMX_OPTS}"
  142. if [ ! -x "$BASEDIR"/logs ]; then
  143. mkdir "$BASEDIR"/logs
  144. fi