Skip to content

Commit

Permalink
Optimize script
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 committed Dec 5, 2024
1 parent 2181ed5 commit 48fee83
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 26 deletions.
64 changes: 45 additions & 19 deletions script/bin/auto.sh
Original file line number Diff line number Diff line change
@@ -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)}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -168,15 +193,16 @@ restart() {
assertIsInputVersion
stop
start
echo "........................................Restart Successfully........................................"
echo -e "${GREEN}........................................Restart Successfully........................................$RESET"

}

restartWithJmx() {
echo ""
assertIsInputVersion
stop
startWithJmx
echo "........................................Restart with Jmx Successfully........................................"
echo -e ".$GREEN.......................................Restart with Jmx Successfully........................................$RESET"
}

case "$1" in
Expand Down
2 changes: 1 addition & 1 deletion script/bin/init_check_network.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -x

EXTERNAL_CONNECTIVITY_CHECK_URL="www.baidu.com"

Expand Down
2 changes: 1 addition & 1 deletion script/bin/init_db.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -x

DINKY_HOME_PARAMS=$1
DB_ENV_FILE=$2
Expand Down
2 changes: 1 addition & 1 deletion script/bin/init_env.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -x

DINKY_HOME_PARAMS=$1
ENV_FILE=$2
Expand Down
2 changes: 1 addition & 1 deletion script/bin/init_flink_dependences.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -x

CURRENT_FLINK_FULL_VERSION=$1
FLINK_VERSION_SCAN=$2
Expand Down
2 changes: 1 addition & 1 deletion script/bin/init_hadoop_dependences.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -x

EXTENDS_HOME=$1

Expand Down
2 changes: 1 addition & 1 deletion script/bin/init_jdbc_driver.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -x

DINKY_LIB_DIR=$1

Expand Down
2 changes: 1 addition & 1 deletion script/bin/init_tools_main.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -x

ENV_FILE="/etc/profile.d/dinky_env"
if [ -f "${ENV_FILE}" ]; then
Expand Down

0 comments on commit 48fee83

Please sign in to comment.