From 67432dc0b06b7623b9b2e0ab18c5078c9f94ad9a Mon Sep 17 00:00:00 2001 From: lahmxu Date: Tue, 29 Aug 2023 23:10:06 +0800 Subject: [PATCH] [type:refactor] Optimizing the startup script --- .../src/main/resources/bin/run-class.sh | 102 ++++++++++++++++++ .../src/main/resources/bin/start.sh | 9 +- .../src/main/resources/bin/run-class.sh | 97 +++++++++++++++++ .../src/main/resources/bin/start.sh | 8 +- 4 files changed, 204 insertions(+), 12 deletions(-) create mode 100644 shenyu-dist/shenyu-admin-dist/src/main/resources/bin/run-class.sh create mode 100644 shenyu-dist/shenyu-bootstrap-dist/src/main/resources/bin/run-class.sh diff --git a/shenyu-dist/shenyu-admin-dist/src/main/resources/bin/run-class.sh b/shenyu-dist/shenyu-admin-dist/src/main/resources/bin/run-class.sh new file mode 100644 index 000000000000..ad3a01cd314f --- /dev/null +++ b/shenyu-dist/shenyu-admin-dist/src/main/resources/bin/run-class.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +cd `dirname $0` +cd .. +DEPLOY_DIR=`pwd` +EXT_LIB=${DEPLOY_DIR}/ext-lib +LIB=${DEPLOY_DIR}/lib + +lib_regex="^"$LIB"/(java|jakarta|reactor|netty|tomcat|spring|mybatis|shenyu).*\.jar$" +lib_exclude_file() { + file=$1 + if [ -z "$(echo "$file" | grep -E "$lib_regex")" ] ; then + return 0 + else + return 1 + fi +} + +# conf files +for file in "$DEPLOY_DIR"/conf/*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +# lib files +for file in "$DEPLOY_DIR"/lib/java*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/jakarta*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/reactor*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/netty*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/tomcat*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/spring*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/mybatis*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/shenyu*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/*; +do + if lib_exclude_file "$file"; then + CLASS_PATH="$CLASS_PATH":"$file" + fi +done + +# ext_lib files +for file in "$EXT_LIB"/*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +if [ -z "$JAVA_HOME" ]; then + JAVA="java" +else + JAVA="$JAVA_HOME/bin/java" +fi + +nohup "$JAVA" -cp "$CLASS_PATH" "$@" + diff --git a/shenyu-dist/shenyu-admin-dist/src/main/resources/bin/start.sh b/shenyu-dist/shenyu-admin-dist/src/main/resources/bin/start.sh index 5a5a506690fc..150f44ad91b1 100644 --- a/shenyu-dist/shenyu-admin-dist/src/main/resources/bin/start.sh +++ b/shenyu-dist/shenyu-admin-dist/src/main/resources/bin/start.sh @@ -26,11 +26,8 @@ LOGS_DIR=${DEPLOY_DIR}/logs if [ ! -d ${LOGS_DIR} ]; then mkdir ${LOGS_DIR} fi - LOG_FILES=${LOGS_DIR}/shenyu-admin.log -EXT_LIB=${DEPLOY_DIR}/ext-lib -CLASS_PATH=.:${DEPLOY_DIR}/conf:${DEPLOY_DIR}/lib/*:${EXT_LIB}/* if [ -z "${ADMIN_JVM}" ]; then JAVA_OPTS=" -server -Xmx2g -Xms2g -Xmn1g -Xss328k -XX:+DisableExplicitGC -XX:LargePageSizeInBytes=128m" version=`java -version 2>&1 | sed '1!d' | sed -e 's/"//g' | awk '{print $3}'` @@ -49,8 +46,8 @@ else fi MAIN_CLASS=org.apache.shenyu.admin.ShenyuAdminBootstrap -echo "Starting the $SERVER_NAME ..." -nohup java ${JAVA_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${LOG_FILES} 2>&1 & -sleep 1 +echo "Starting the $SERVER_NAME ..." echo "Please check the log files: $LOG_FILES" + +exec $DEPLOY_DIR/bin/run-class.sh $JAVA_OPTS $MAIN_CLASS >> $LOG_FILES 2>&1 & "$@" diff --git a/shenyu-dist/shenyu-bootstrap-dist/src/main/resources/bin/run-class.sh b/shenyu-dist/shenyu-bootstrap-dist/src/main/resources/bin/run-class.sh new file mode 100644 index 000000000000..c88cddf8e06a --- /dev/null +++ b/shenyu-dist/shenyu-bootstrap-dist/src/main/resources/bin/run-class.sh @@ -0,0 +1,97 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +cd `dirname $0` +cd .. +DEPLOY_DIR=`pwd` +EXT_LIB=${DEPLOY_DIR}/ext-lib +LIB=${DEPLOY_DIR}/lib + +lib_regex="^"$LIB"/(java|jakarta|jackson|reactor|netty|spring|shenyu).*\.jar$" +lib_exclude_file() { + file=$1 + if [ -z "$(echo "$file" | grep -E "$lib_regex")" ] ; then + return 0 + else + return 1 + fi +} + +# conf files +for file in "$DEPLOY_DIR"/conf/*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +# lib files +for file in "$DEPLOY_DIR"/lib/java*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/jakarta*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/jackson*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/reactor*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/netty*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/spring*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/shenyu*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +for file in "$DEPLOY_DIR"/lib/*; +do + if lib_exclude_file "$file"; then + CLASS_PATH="$CLASS_PATH":"$file" + fi +done + +# ext_lib files +for file in "$EXT_LIB"/*; +do + CLASS_PATH="$CLASS_PATH":"$file" +done + +if [ -z "$JAVA_HOME" ]; then + JAVA="java" +else + JAVA="$JAVA_HOME/bin/java" +fi + +nohup "$JAVA" -cp "$CLASS_PATH" "$@" + diff --git a/shenyu-dist/shenyu-bootstrap-dist/src/main/resources/bin/start.sh b/shenyu-dist/shenyu-bootstrap-dist/src/main/resources/bin/start.sh index 421aba362241..2f5f0849b4c2 100644 --- a/shenyu-dist/shenyu-bootstrap-dist/src/main/resources/bin/start.sh +++ b/shenyu-dist/shenyu-bootstrap-dist/src/main/resources/bin/start.sh @@ -28,9 +28,7 @@ if [ ! -d ${LOGS_DIR} ]; then fi LOG_FILES=${LOGS_DIR}/shenyu-bootstrap.log -EXT_LIB=${DEPLOY_DIR}/ext-lib -CLASS_PATH=.:${DEPLOY_DIR}/conf:${DEPLOY_DIR}/lib/*:${EXT_LIB}/* if [ -z "${BOOT_JVM}" ]; then JAVA_OPTS=" -server -Xmx4g -Xms4g -Xmn1g -Xss512k -XX:+DisableExplicitGC -XX:LargePageSizeInBytes=128m" version=`java -version 2>&1 | sed '1!d' | sed -e 's/"//g' | awk '{print $3}'` @@ -51,8 +49,6 @@ fi MAIN_CLASS=org.apache.shenyu.bootstrap.ShenyuBootstrapApplication echo "Starting the $SERVER_NAME ..." - -nohup java ${JAVA_OPTS} -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${LOG_FILES} 2>&1 & - -sleep 1 echo "Please check the log files: $LOG_FILES" + +exec $DEPLOY_DIR/bin/run-class.sh $JAVA_OPTS $MAIN_CLASS >> $LOG_FILES 2>&1 & "$@" \ No newline at end of file