2019-05-22 08:18:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Copyright 1999-2018 Alibaba Group Holding Ltd.
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
set -x
|
2022-08-12 09:47:51 +00:00
|
|
|
export CUSTOM_SEARCH_NAMES="application"
|
|
|
|
export CUSTOM_SEARCH_LOCATIONS=file:${BASE_DIR}/conf/
|
2020-06-05 10:40:28 +00:00
|
|
|
export MEMBER_LIST=""
|
2019-05-22 08:18:41 +00:00
|
|
|
PLUGINS_DIR="/home/nacos/plugins/peer-finder"
|
2021-01-15 17:16:03 +00:00
|
|
|
function print_servers() {
|
2022-11-08 04:06:22 +00:00
|
|
|
if [[ ! -d "${PLUGINS_DIR}" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
echo "" >"$CLUSTER_CONF"
|
2019-05-22 08:18:41 +00:00
|
|
|
for server in ${NACOS_SERVERS}; do
|
2021-01-15 17:16:03 +00:00
|
|
|
echo "$server" >>"$CLUSTER_CONF"
|
2019-05-22 08:18:41 +00:00
|
|
|
done
|
2021-01-15 17:16:03 +00:00
|
|
|
else
|
2019-05-22 08:18:41 +00:00
|
|
|
bash $PLUGINS_DIR/plugin.sh
|
2021-01-15 17:16:03 +00:00
|
|
|
sleep 30
|
|
|
|
fi
|
2019-05-22 08:18:41 +00:00
|
|
|
}
|
|
|
|
#===========================================================================================
|
|
|
|
# JVM Configuration
|
|
|
|
#===========================================================================================
|
2023-06-15 03:18:20 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 "
|
2019-05-22 08:18:41 +00:00
|
|
|
if [[ "${MODE}" == "standalone" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Xms${JVM_XMS} -Xmx${JVM_XMX} -Xmn${JVM_XMN}"
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.standalone=true"
|
2019-05-22 08:18:41 +00:00
|
|
|
else
|
2020-06-05 10:40:28 +00:00
|
|
|
if [[ "${EMBEDDED_STORAGE}" == "embedded" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -DembeddedStorage=true"
|
|
|
|
fi
|
2019-07-07 14:35:44 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -server -Xms${JVM_XMS} -Xmx${JVM_XMX} -Xmn${JVM_XMN} -XX:MetaspaceSize=${JVM_MS} -XX:MaxMetaspaceSize=${JVM_MMS}"
|
|
|
|
if [[ "${NACOS_DEBUG}" == "y" ]]; then
|
|
|
|
JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
|
|
|
|
fi
|
2019-05-22 08:18:41 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BASE_DIR}/logs/java_heapdump.hprof"
|
|
|
|
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages"
|
|
|
|
print_servers
|
|
|
|
fi
|
|
|
|
|
|
|
|
#===========================================================================================
|
|
|
|
# Setting system properties
|
|
|
|
#===========================================================================================
|
|
|
|
# set mode that Nacos Server function of split
|
|
|
|
if [[ "${FUNCTION_MODE}" == "config" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=config"
|
2019-05-22 08:18:41 +00:00
|
|
|
elif [[ "${FUNCTION_MODE}" == "naming" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=naming"
|
2019-05-22 08:18:41 +00:00
|
|
|
fi
|
|
|
|
# set nacos server ip
|
|
|
|
if [[ ! -z "${NACOS_SERVER_IP}" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.server.ip=${NACOS_SERVER_IP}"
|
2019-05-22 08:18:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -z "${USE_ONLY_SITE_INTERFACES}" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.inetutils.use-only-site-local-interfaces=${USE_ONLY_SITE_INTERFACES}"
|
2019-05-22 08:18:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -z "${PREFERRED_NETWORKS}" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.inetutils.preferred-networks=${PREFERRED_NETWORKS}"
|
2019-05-22 08:18:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -z "${IGNORED_INTERFACES}" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.inetutils.ignored-interfaces=${IGNORED_INTERFACES}"
|
2019-05-22 08:18:41 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-06 10:55:42 +00:00
|
|
|
### If turn on auth system:
|
|
|
|
if [[ ! -z "${NACOS_AUTH_ENABLE}" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.core.auth.enabled=${NACOS_AUTH_ENABLE}"
|
2020-03-06 10:55:42 +00:00
|
|
|
fi
|
|
|
|
|
2019-05-22 08:18:41 +00:00
|
|
|
if [[ "${PREFER_HOST_MODE}" == "hostname" ]]; then
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.preferHostnameOverIp=true"
|
2021-06-29 10:10:48 +00:00
|
|
|
fi
|
2020-06-05 10:40:28 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.member.list=${MEMBER_LIST}"
|
|
|
|
|
2019-05-22 08:18:41 +00:00
|
|
|
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
|
2021-01-15 17:16:03 +00:00
|
|
|
if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]]; then
|
2019-05-22 08:18:41 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${BASE_DIR}/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400"
|
|
|
|
else
|
2023-03-21 11:51:06 +00:00
|
|
|
JAVA_OPT_EXT_FIX="-Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
|
2019-05-22 08:18:41 +00:00
|
|
|
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"
|
|
|
|
fi
|
|
|
|
|
2023-03-21 11:51:06 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dloader.path=${BASE_DIR}/plugins,${BASE_DIR}/plugins/health,${BASE_DIR}/plugins/cmdb,${BASE_DIR}/plugins/selector"
|
2019-05-22 08:18:41 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}"
|
|
|
|
JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/nacos-server.jar"
|
|
|
|
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
|
2021-01-15 17:16:03 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} --spring.config.additional-location=${CUSTOM_SEARCH_LOCATIONS}"
|
2019-05-22 08:18:41 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} --spring.config.name=${CUSTOM_SEARCH_NAMES}"
|
|
|
|
JAVA_OPT="${JAVA_OPT} --logging.config=${BASE_DIR}/conf/nacos-logback.xml"
|
2019-09-24 01:58:59 +00:00
|
|
|
JAVA_OPT="${JAVA_OPT} --server.max-http-header-size=524288"
|
2019-05-22 08:18:41 +00:00
|
|
|
|
2021-06-29 08:07:37 +00:00
|
|
|
echo "Nacos is starting, you can docker logs your container"
|
|
|
|
exec $JAVA ${JAVA_OPT}
|