From 48fee83b55579738c013e9acde52dfcab15c96d6 Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Thu, 5 Dec 2024 14:38:16 +0800 Subject: [PATCH] Optimize script --- script/bin/auto.sh | 64 +++++++++++++++++++-------- script/bin/init_check_network.sh | 2 +- script/bin/init_db.sh | 2 +- script/bin/init_env.sh | 2 +- script/bin/init_flink_dependences.sh | 2 +- script/bin/init_hadoop_dependences.sh | 2 +- script/bin/init_jdbc_driver.sh | 2 +- script/bin/init_tools_main.sh | 2 +- 8 files changed, 52 insertions(+), 26 deletions(-) diff --git a/script/bin/auto.sh b/script/bin/auto.sh index 339b5374c8..37b10141f3 100644 --- a/script/bin/auto.sh +++ b/script/bin/auto.sh @@ -1,8 +1,34 @@ #!/bin/bash - # debug mode #set -x +export RED='\033[31m' +export GREEN='\033[32m' +export YELLOW='\033[33m' +export BLUE='\033[34m' +export MAGENTA='\033[35m' +export CYAN='\033[36m' +export RESET='\033[0m' + + + +if [ -z "${DINKY_HOME}" ]; then + echo -e "${RED}DINKY_HOME environment variable is not set. Attempting to determine the correct path...${RESET}" + + SOURCE="${BASH_SOURCE[0]}" + while [ -h "$SOURCE" ]; do + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" + done + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + export DINKY_HOME="$(dirname "$DIR")" + echo -e "${GREEN}DINKY_HOME is set to: ${DINKY_HOME}${RESET}" +else + echo -e "${GREEN}DINKY_HOME is already set to: ${DINKY_HOME}${RESET}" +fi + + FLINK_VERSION=${2} DINKY_HOME=${DINKY_HOME:-$(cd "$(dirname "$0")"; cd ..; pwd)} @@ -34,13 +60,13 @@ if [ -z "${FLINK_VERSION}" ]; then fi fi -echo "DINKY_HOME : ${APP_HOME} , JAVA_VERSION : ${JAVA_VERSION} , FLINK_VERSION : ${FLINK_VERSION}" +echo -e "${GREEN}DINKY_HOME : ${APP_HOME} , JAVA_VERSION : ${JAVA_VERSION} , FLINK_VERSION : ${FLINK_VERSION} ${RESET}" # Check whether the flink version is specified assertIsInputVersion() { # If FLINK_VERSION is still empty, prompt the user to enter the Flink version if [ -z "${FLINK_VERSION}" ]; then - echo "The flink version is not specified and the flink version cannot be found under the extends directory. Please specify the flink version." + echo -e "${RED}The flink version is not specified and the flink version cannot be found under the extends directory. Please specify the flink version${RESET}" exit 1 fi } @@ -74,21 +100,21 @@ JVM_OPTS="-Xms512M -Xmx2048M -XX:PermSize=512M -XX:MaxPermSize=1024M" PID_PATH="${APP_HOME}/run" if [ -d "${PID_PATH}" ];then - echo "${PID_PATH} is already exist." >> /dev/null + echo -e "${GREEN} ${PID_PATH} is already exist.${PID_PATH}${RESET}" >> /dev/null else mkdir -p "${PID_PATH}" fi # Check whether the pid file exists if [ -f "${PID_PATH}/${PID_FILE}" ];then - echo "${PID_PATH}/${PID_FILE} is already exist." >> /dev/null + echo -e "${GREEN} ${PID_PATH}/${PID_FILE} is already exist. ${RESET}" >> /dev/null else touch "${PID_PATH}"/${PID_FILE} fi tips() { echo "" - echo "WARNING!!!......Tips, please use command: sh auto.sh [start|startOnPending|startWithJmx|stop|restart|restartWithJmx|status]. For example: sh auto.sh start " + echo -e "${YELLOW}WARNING!!!......Tips, please use command: sh auto.sh [start|startOnPending|startWithJmx|stop|restart|restartWithJmx|status]. For example: sh auto.sh start ${RESET}" echo "" exit 1 } @@ -104,10 +130,10 @@ start() { if [ -z "$pid" ]; then nohup java ${PARAMS_OPT} ${JVM_OPTS} ${OOM_OPT} ${GC_OPT} -Xverify:none -cp "${CLASS_PATH}" org.dinky.Dinky ${JAR_PARAMS_OPT} > ${DINKY_LOG_PATH}/dinky-start.log 2>&1 & echo $! >"${PID_PATH}"/${PID_FILE} - echo "........................................Start Dinky Done........................................" - echo "current log path : ${DINKY_LOG_PATH}/dinky-start.log , you can execute tail -fn1000 ${DINKY_LOG_PATH}/dinky-start.log to watch the log" + echo -e "${GREEN}........................................Start Dinky Successfully........................................${RESET}" + echo -e "${GREEN}current log path : ${DINKY_LOG_PATH}/dinky-start.log , you can execute tail -fn1000 ${DINKY_LOG_PATH}/dinky-start.log to watch the log${RESET}" else - echo "Dinky pid $pid is in ${PID_PATH}/${PID_FILE}, Please stop first !!!" + echo -e "$YELLOW Dinky pid $pid is in ${PID_PATH}/${PID_FILE}, Please stop first !!!$RESET" fi } @@ -116,9 +142,9 @@ startOnPending() { updatePid if [ -z "$pid" ]; then java ${PARAMS_OPT} ${JVM_OPTS} ${OOM_OPT} ${GC_OPT} -Xverify:none -cp "${CLASS_PATH}" org.dinky.Dinky ${JAR_PARAMS_OPT} - echo "........................................Start Dinky Successfully........................................" + echo -e "$GREEN........................................Start Dinky Successfully........................................$RESET" else - echo "Dinky pid $pid is in ${PID_PATH}/${PID_FILE}, Please stop first !!!" + echo -e "$YELLOW Dinky pid $pid is in ${PID_PATH}/${PID_FILE}, Please stop first !!!$RESET" fi } @@ -129,10 +155,9 @@ startWithJmx() { nohup java ${PARAMS_OPT} ${JVM_OPTS} ${OOM_OPT} ${GC_OPT} -Xverify:none "${JMX}" -cp "${CLASS_PATH}" org.dinky.Dinky ${JAR_PARAMS_OPT} > ${DINKY_LOG_PATH}/dinky-start.log 2>&1 & # echo $! >"${PID_PATH}"/${PID_FILE} updatePid - echo "........................................Start Dinky with Jmx Successfully..................................... - ..." + echo -e "$GREEN........................................Start Dinky with Jmx Successfully........................................$RESET" else - echo "Dinky pid $pid is in ${PID_PATH}/${PID_FILE}, Please stop first !!!" + echo -e "$YELLOW Dinky pid $pid is in ${PID_PATH}/${PID_FILE}, Please stop first !!!$RESET" fi } @@ -144,7 +169,7 @@ stop() { else kill -9 $pid sleep 1 - echo "........................................Stop Dinky Successfully....................................." + echo -e "$GREEN........................................Stop Dinky Successfully.....................................$RESET" rm -f "${PID_PATH}"/${PID_FILE} fi } @@ -153,12 +178,12 @@ status() { updatePid if [ -z $pid ]; then echo "" - echo "Service ${JAR_NAME} is not running!" + echo -e "${RED}Service ${JAR_NAME} is not running!${RESET}" echo "" exit 1 else echo "" - echo "Service ${JAR_NAME} is running. It's pid=${pid}" + echo -e "${GREEN}Service ${JAR_NAME} is running. It's pid=${pid}${RESET}" echo "" fi } @@ -168,7 +193,8 @@ restart() { assertIsInputVersion stop start - echo "........................................Restart Successfully........................................" + echo -e "${GREEN}........................................Restart Successfully........................................$RESET" + } restartWithJmx() { @@ -176,7 +202,7 @@ restartWithJmx() { assertIsInputVersion stop startWithJmx - echo "........................................Restart with Jmx Successfully........................................" + echo -e ".$GREEN.......................................Restart with Jmx Successfully........................................$RESET" } case "$1" in diff --git a/script/bin/init_check_network.sh b/script/bin/init_check_network.sh index 3502143c7c..66b5cd105b 100644 --- a/script/bin/init_check_network.sh +++ b/script/bin/init_check_network.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -x EXTERNAL_CONNECTIVITY_CHECK_URL="www.baidu.com" diff --git a/script/bin/init_db.sh b/script/bin/init_db.sh index 6e518dc2f8..22b7372ab2 100644 --- a/script/bin/init_db.sh +++ b/script/bin/init_db.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -x DINKY_HOME_PARAMS=$1 DB_ENV_FILE=$2 diff --git a/script/bin/init_env.sh b/script/bin/init_env.sh index f500fa06f8..94242d380c 100644 --- a/script/bin/init_env.sh +++ b/script/bin/init_env.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -x DINKY_HOME_PARAMS=$1 ENV_FILE=$2 diff --git a/script/bin/init_flink_dependences.sh b/script/bin/init_flink_dependences.sh index 4f5b3d7501..451d3b214d 100644 --- a/script/bin/init_flink_dependences.sh +++ b/script/bin/init_flink_dependences.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -x CURRENT_FLINK_FULL_VERSION=$1 FLINK_VERSION_SCAN=$2 diff --git a/script/bin/init_hadoop_dependences.sh b/script/bin/init_hadoop_dependences.sh index 261760e50c..c080a44188 100644 --- a/script/bin/init_hadoop_dependences.sh +++ b/script/bin/init_hadoop_dependences.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -x EXTENDS_HOME=$1 diff --git a/script/bin/init_jdbc_driver.sh b/script/bin/init_jdbc_driver.sh index 732d03fc93..63631af604 100644 --- a/script/bin/init_jdbc_driver.sh +++ b/script/bin/init_jdbc_driver.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -x DINKY_LIB_DIR=$1 diff --git a/script/bin/init_tools_main.sh b/script/bin/init_tools_main.sh index f48f02bfcf..1b2aae6821 100644 --- a/script/bin/init_tools_main.sh +++ b/script/bin/init_tools_main.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -x ENV_FILE="/etc/profile.d/dinky_env" if [ -f "${ENV_FILE}" ]; then