docker-startup.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # Copyright 1999-2018 Alibaba Group Holding Ltd.
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing permissions and
  12. # limitations under the License.
  13. set -x
  14. export DEFAULT_SEARCH_LOCATIONS="classpath:/,classpath:/config/,file:./,file:./config/"
  15. export CUSTOM_SEARCH_LOCATIONS=${DEFAULT_SEARCH_LOCATIONS},file:${BASE_DIR}/conf/,${BASE_DIR}/init.d/
  16. export CUSTOM_SEARCH_NAMES="application,custom"
  17. export MEMBER_LIST=""
  18. PLUGINS_DIR="/home/nacos/plugins/peer-finder"
  19. function print_servers(){
  20. if [[ ! -d "${PLUGINS_DIR}" ]]; then
  21. echo "" > "$CLUSTER_CONF"
  22. for server in ${NACOS_SERVERS}; do
  23. echo "$server" >> "$CLUSTER_CONF"
  24. done
  25. else
  26. bash $PLUGINS_DIR/plugin.sh
  27. sleep 30
  28. fi
  29. }
  30. #===========================================================================================
  31. # JVM Configuration
  32. #===========================================================================================
  33. if [[ "${MODE}" == "standalone" ]]; then
  34. JAVA_OPT="${JAVA_OPT} -Xms${JVM_XMS} -Xmx${JVM_XMX} -Xmn${JVM_XMN}"
  35. JAVA_OPT="${JAVA_OPT} -Dnacos.standalone=true"
  36. else
  37. if [[ "${EMBEDDED_STORAGE}" == "embedded" ]]; then
  38. JAVA_OPT="${JAVA_OPT} -DembeddedStorage=true"
  39. fi
  40. JAVA_OPT="${JAVA_OPT} -server -Xms${JVM_XMS} -Xmx${JVM_XMX} -Xmn${JVM_XMN} -XX:MetaspaceSize=${JVM_MS} -XX:MaxMetaspaceSize=${JVM_MMS}"
  41. if [[ "${NACOS_DEBUG}" == "y" ]]; then
  42. JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
  43. fi
  44. JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BASE_DIR}/logs/java_heapdump.hprof"
  45. JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages"
  46. print_servers
  47. fi
  48. #===========================================================================================
  49. # Setting system properties
  50. #===========================================================================================
  51. # set mode that Nacos Server function of split
  52. if [[ "${FUNCTION_MODE}" == "config" ]]; then
  53. JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=config"
  54. elif [[ "${FUNCTION_MODE}" == "naming" ]]; then
  55. JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=naming"
  56. fi
  57. # set nacos server ip
  58. if [[ ! -z "${NACOS_SERVER_IP}" ]]; then
  59. JAVA_OPT="${JAVA_OPT} -Dnacos.server.ip=${NACOS_SERVER_IP}"
  60. fi
  61. if [[ ! -z "${USE_ONLY_SITE_INTERFACES}" ]]; then
  62. JAVA_OPT="${JAVA_OPT} -Dnacos.inetutils.use-only-site-local-interfaces=${USE_ONLY_SITE_INTERFACES}"
  63. fi
  64. if [[ ! -z "${PREFERRED_NETWORKS}" ]]; then
  65. JAVA_OPT="${JAVA_OPT} -Dnacos.inetutils.preferred-networks=${PREFERRED_NETWORKS}"
  66. fi
  67. if [[ ! -z "${IGNORED_INTERFACES}" ]]; then
  68. JAVA_OPT="${JAVA_OPT} -Dnacos.inetutils.ignored-interfaces=${IGNORED_INTERFACES}"
  69. fi
  70. ### If turn on auth system:
  71. if [[ ! -z "${NACOS_AUTH_ENABLE}" ]]; then
  72. JAVA_OPT="${JAVA_OPT} -Dnacos.core.auth.enabled=${NACOS_AUTH_ENABLE}"
  73. fi
  74. if [[ "${PREFER_HOST_MODE}" == "hostname" ]]; then
  75. JAVA_OPT="${JAVA_OPT} -Dnacos.preferHostnameOverIp=true"
  76. fi
  77. JAVA_OPT="${JAVA_OPT} -Dnacos.member.list=${MEMBER_LIST}"
  78. JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
  79. if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] ; then
  80. JAVA_OPT="${JAVA_OPT} -cp .:${BASE_DIR}/plugins/cmdb/*.jar:${BASE_DIR}/plugins/mysql/*.jar"
  81. JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${BASE_DIR}/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400"
  82. else
  83. JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:${BASE_DIR}/plugins/health:${BASE_DIR}/plugins/cmdb:${BASE_DIR}/plugins/mysql"
  84. JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
  85. fi
  86. JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}"
  87. JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/nacos-server.jar"
  88. JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
  89. JAVA_OPT="${JAVA_OPT} --spring.config.location=${CUSTOM_SEARCH_LOCATIONS}"
  90. JAVA_OPT="${JAVA_OPT} --spring.config.name=${CUSTOM_SEARCH_NAMES}"
  91. JAVA_OPT="${JAVA_OPT} --logging.config=${BASE_DIR}/conf/nacos-logback.xml"
  92. JAVA_OPT="${JAVA_OPT} --server.max-http-header-size=524288"
  93. echo "nacos is starting,you can check the ${BASE_DIR}/logs/start.out"
  94. echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out 2>&1 &
  95. nohup $JAVA ${JAVA_OPT} > ${BASE_DIR}/logs/start.out 2>&1 < /dev/null