nacos/distribution/bin/startup.sh

119 lines
4.1 KiB
Bash
Raw Normal View History

2018-07-21 00:27:23 +08:00
#!/bin/sh
# 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.
2019-01-27 01:40:26 +08:00
cygwin=false
darwin=false
os400=false
case "`uname`" in
CYGWIN*) cygwin=true;;
Darwin*) darwin=true;;
OS400*) os400=true;;
esac
2018-07-21 00:27:23 +08:00
error_exit ()
{
echo "ERROR: $1 !!"
exit 1
}
2019-01-30 17:40:16 +08:00
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/opt/taobao/java
[ ! -e "$JAVA_HOME/bin/java" ] && unset JAVA_HOME
2019-01-27 01:40:26 +08:00
if [ -z "$JAVA_HOME" ]; then
if $darwin; then
2018-07-21 00:27:23 +08:00
2019-01-27 01:40:26 +08:00
if [ -x '/usr/libexec/java_home' ] ; then
export JAVA_HOME=`/usr/libexec/java_home`
elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
fi
else
JAVA_PATH=`dirname $(readlink -f $(which javac))`
if [ "x$JAVA_PATH" != "x" ]; then
export JAVA_HOME=`dirname $JAVA_PATH 2>/dev/null`
fi
fi
if [ -z "$JAVA_HOME" ]; then
error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better!"
fi
fi
2018-07-21 00:27:23 +08:00
export MODE="cluster"
while getopts ":m:" opt
do
case $opt in
m)
MODE=$OPTARG
;;
?)
echo "Unknown parameter"
2018-07-21 00:27:23 +08:00
exit 1;;
esac
done
export JAVA_HOME
export JAVA="$JAVA_HOME/bin/java"
export BASE_DIR=`cd $(dirname $0)/..; pwd`
export DEFAULT_SEARCH_LOCATIONS="classpath:/,classpath:/config/,file:./,file:./config/"
export CUSTOM_SEARCH_LOCATIONS=${DEFAULT_SEARCH_LOCATIONS},file:${BASE_DIR}/conf/
2018-07-21 00:27:23 +08:00
#===========================================================================================
# JVM Configuration
#===========================================================================================
if [[ "${MODE}" == "standalone" ]]; then
2018-11-16 14:22:12 +08:00
JAVA_OPT="${JAVA_OPT} -Xms512m -Xmx512m -Xmn256m"
2018-07-21 00:27:23 +08:00
JAVA_OPT="${JAVA_OPT} -Dnacos.standalone=true"
2018-11-16 14:22:12 +08:00
else
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${BASE_DIR}/logs/java_heapdump.hprof"
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages"
fi
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] ; then
2019-01-18 10:57:44 +08:00
JAVA_OPT="${JAVA_OPT} -cp .:${BASE_DIR}/plugins/cmdb/*.jar"
JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${BASE_DIR}/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400"
2018-11-16 14:22:12 +08:00
else
2019-01-18 10:57:44 +08:00
JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:${BASE_DIR}/plugins/cmdb"
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"
2018-07-21 00:27:23 +08:00
fi
2019-01-18 10:57:44 +08:00
2018-11-16 14:22:12 +08:00
JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}"
2018-07-21 00:27:23 +08:00
JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/nacos-server.jar"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} --spring.config.location=${CUSTOM_SEARCH_LOCATIONS}"
JAVA_OPT="${JAVA_OPT} --logging.config=${BASE_DIR}/conf/nacos-logback.xml"
2018-11-16 14:22:12 +08:00
2018-07-21 00:27:23 +08:00
if [ ! -d "${BASE_DIR}/logs" ]; then
mkdir ${BASE_DIR}/logs
fi
2018-11-07 18:20:09 +08:00
echo "$JAVA ${JAVA_OPT}"
2018-11-15 22:45:53 +08:00
if [[ "${MODE}" == "standalone" ]]; then
2018-11-16 14:22:12 +08:00
echo "nacos is starting"
2018-11-15 22:45:53 +08:00
$JAVA ${JAVA_OPT}
else
if [ ! -f "${BASE_DIR}/logs/start.out" ]; then
2018-11-16 14:22:12 +08:00
touch "${BASE_DIR}/logs/start.out"
2018-11-15 22:45:53 +08:00
fi
2018-11-16 14:22:12 +08:00
echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out 2>&1 &
2018-11-15 22:45:53 +08:00
nohup $JAVA ${JAVA_OPT} >> ${BASE_DIR}/logs/start.out 2>&1 &
echo "nacos is startingyou can check the ${BASE_DIR}/logs/start.out"
2019-01-04 14:16:15 +08:00
fi