Skip to content

Commit

Permalink
[Optimization] Optimize some script (DataLinkDC#4006)
Browse files Browse the repository at this point in the history
Co-authored-by: Zzm0809 <[email protected]>
Co-authored-by: GH Action - Upstream Sync <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent 7c43295 commit a1613a1
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 74 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
1 change: 1 addition & 0 deletions script/bin/init_check_network.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -x

EXTERNAL_CONNECTIVITY_CHECK_URL="www.baidu.com"

Expand Down
85 changes: 51 additions & 34 deletions script/bin/init_db.sh
Original file line number Diff line number Diff line change
@@ -1,62 +1,79 @@
#!/bin/bash
set -x

DINKY_HOME=$1
DINKY_HOME_PARAMS=$1
DB_ENV_FILE=$2

echo -e "${GREEN}====================== The database configuration file is initialized ======================${RESET}"

if [ -z "$DINKY_HOME" ]; then
if [ -z "$DINKY_HOME_PARAMS" ]; then
echo -e "${RED}The parameter is wrong, please check!${RESET}"
exit 1
fi

while true; do
read -p "Please select a database type (1.MySQL 2.PostgresSQL):" db_type
read -p "Please enter the database address (hostname or IP, default localhost): " -i "localhost" db_host
read -p "Please enter the database port (default 3306): " -i 3306 db_port
read -p "Please enter a database name (default dinky): " -i "dinky" db_name
read -p "Please enter the database username (default dinky):" -i "dinky" db_username
read -s -p "Please enter the database password (default dinky):" -i "dinky" db_password
read -e -p "Please select a database type (1.MySQL 2.PostgresSQL):" db_type
while [ -z "$db_type" ]; do
read -e -p "Please select a database type (1.MySQL 2.PostgresSQL):" db_type
done
read -e -p "Please enter the database address (hostname or IP, default localhost): " -i "localhost" db_host
read -p "Please enter the database port : " db_port
read -e -p "Please enter a database name (default dinky): " -i "dinky" db_name
read -e -p "Please enter the database username (default dinky):" -i "dinky" db_username
read -s -p "Please enter the database password (default dinky):" db_password
echo

db_type=$(echo "$db_type" | tr -d '[:space:]')
db_host=$(echo "$db_host" | tr -d '[:space:]')
db_port=$(echo "$db_port" | tr -d '[:space:]')
db_name=$(echo "$db_name" | tr -d '[:space:]')
db_username=$(echo "$db_username" | tr -d '[:space:]')
db_password=$(echo "$db_password" | tr -d '[:space:]')

db_type=$(echo ${db_type} | tr -d '[:space:]')
db_host=$(echo ${db_host:-"localhost"} | tr -d '[:space:]')
db_name=$(echo ${db_name:-"dinky"}| tr -d '[:space:]')
db_username=$(echo ${db_username:-"dinky"} | tr -d '[:space:]')
db_password=$(echo ${db_password:-"dinky"} | tr -d '[:space:]')
if [ "$db_type" == 1 ]; then
db_port=$(echo ${db_port:-"3306"} | tr -d '[:space:]')
else
db_port=$(echo ${db_port:-"5432"} | tr -d '[:space:]')
fi


case $db_type in
1)
echo -e "${YELLOW}Configuring MySQL database related information...${RESET}"
config_file="${DINKY_HOME}/config/application-mysql.yml"
config_file="${DINKY_HOME_PARAMS}/config/application-mysql.yml"
echo -e "${GREEN} The automatic initialization script uses the export environment variable method to support the loading of environment variables of the data source. The configuration file is:${config_file} ${RESET}"
echo "export DB_ACTIVE=mysql" >> /etc/profile
echo "export MYSQL_ADDR=${db_host}:${db_port}" >> /etc/profile
echo "export MYSQL_DATABASE=${db_name}" >> /etc/profile
echo "export MYSQL_USERNAME=${db_username}" >> /etc/profile
echo "export MYSQL_PASSWORD=${db_password}" >> /etc/profile
source /etc/profile

add_to_env "DB_ACTIVE" "mysql" "$DB_ENV_FILE"
add_to_env "MYSQL_ADDR" "${db_host}:${db_port}" "$DB_ENV_FILE"
add_to_env "MYSQL_DATABASE" "${db_name}" "$DB_ENV_FILE"
add_to_env "MYSQL_USERNAME" "${db_username}" "$DB_ENV_FILE"
add_to_env "MYSQL_PASSWORD" "${db_password}" "$DB_ENV_FILE"


sleep 2
source "$DB_ENV_FILE"

echo -e "${GREEN}MySQLThe configuration of database related information is completed. Please confirm whether the following configuration is correct:${RESET}"
grep -E '^(export DB_ACTIVE|export MYSQL_ADDR|export MYSQL_DATABASE|export MYSQL_USERNAME|export MYSQL_PASSWORD)' /etc/profile | grep -v "^#" | grep -v "^$"
grep -E '^(export DB_ACTIVE|export MYSQL_ADDR|export MYSQL_DATABASE|export MYSQL_USERNAME|export MYSQL_PASSWORD)' $DB_ENV_FILE | grep -v "^#" | grep -v "^$"
break
;;
2)
echo -e "${YELLOW}Configuring PostgresSQL database related information...${RESET}"
config_file="${DINKY_HOME}/config/application-pgsql.yml"
echo -e "${YELLOW}Configuring PostgresSQL database related information...${RESET}"
config_file="${DINKY_HOME_PARAMS}/config/application-postgresql.yml"

echo -e "${GREEN}The automatic initialization script uses the export environment variable method to support the loading of environment variables from the data source configuration file. The configuration file is:${config_file} ${RESET}"
echo -e "${GREEN}The automatic initialization script uses the export environment variable method to support the loading of environment variables from the data source configuration file. The configuration file is:${config_file} ${RESET}"

echo "export DB_ACTIVE=pgsql" >> /etc/profile
echo "export POSTGRES_ADDR=${db_host}:${db_port}" >> /etc/profile
echo "export POSTGRES_DB=${db_name}" >> /etc/profile
echo "export POSTGRES_USER=${db_username}" >> /etc/profile
echo "export POSTGRES_PASSWORD=${db_password}" >> /etc/profile
source /etc/profile
add_to_env "DB_ACTIVE" "postgresql" "$DB_ENV_FILE"
add_to_env "POSTGRES_ADDR" "${db_host}:${db_port}" "$DB_ENV_FILE"
add_to_env "POSTGRES_DB" "${db_name}" "$DB_ENV_FILE"
add_to_env "POSTGRES_USER" "${db_username}" "$DB_ENV_FILE"
add_to_env "POSTGRES_PASSWORD" "${db_password}" "$DB_ENV_FILE"
sleep 2
source $DB_ENV_FILE

echo -e "${GREEN}PostgresSQL The configuration of database related information is completed. Please confirm whether the following configuration is correct:${RESET}"
grep -E '^(export DB_ACTIVE|export POSTGRES_ADDR|export POSTGRES_DB|export POSTGRES_USER|export POSTGRES_PASSWORD)' /etc/profile | grep -v "^#" | grep -v "^$"
break
echo -e "${GREEN}PostgresSQL The configuration of database related information is completed. Please confirm whether the following configuration is correct:${RESET}"
grep -E '^(export DB_ACTIVE|export POSTGRES_ADDR|export POSTGRES_DB|export POSTGRES_USER|export POSTGRES_PASSWORD)' $DB_ENV_FILE | grep -v "^#" | grep -v "^$"

break
;;
*)
echo -e "${RED}The entered database type is incorrect, please select the correct database type again.${RESET}"
Expand Down
53 changes: 53 additions & 0 deletions script/bin/init_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -x

DINKY_HOME_PARAMS=$1
ENV_FILE=$2


echo -e "${GREEN}Start configuring DINKY_HOME environment variable...${RESET}"

echo -e "${GREEN}DINKY_HOME environment variable has not been configured, please choose whether to configure.${RESET}"
echo -e "${GREEN}1. Use the automatically obtained DINKY_HOME environment variable${RESET}"
echo -e "${GREEN}2. Manually enter the path of DINKY_HOME${RESET}"
echo -e "${GREEN}3. Cancel configuration${RESET}"
while true; do
read -p "Please enter your choice(1/2/3):" DINKY_HOME_CHOICE
case $DINKY_HOME_CHOICE in
1)
echo -e "${GREEN}Use the automatically obtained DINKY_HOME environment variable${RESET}"
echo -e "${GREEN} The currently obtained path is: $DINKY_HOME_PARAMS to perform automatic configuration${RESET}"
add_to_env "DINKY_HOME" "$DINKY_HOME_PARAMS" "$ENV_FILE"
add_to_env "PATH" "\$DINKY_HOME/bin" "$ENV_FILE"
sleep 2
source $ENV_FILE
echo -e "${GREEN}DINKY_HOME environment variable configuration completed. Please confirm whether the following configuration is correct:${RESET}"
grep -E '^(export DINKY_HOME)' $ENV_FILE | grep -v "^#" | grep -v "^$"
break
;;
2)
read -p "Please enter the path of DINKY_HOME:" dinky_home_path
dinky_home_path=$(echo "$dinky_home_path" | tr -d '[:space:]')
if [ ! -d "$dinky_home_path" ]; then
echo -e "${RED}The path does not exist, please re-enter${RESET}"
read -p "Please enter the path of DINKY_HOME:" dinky_home_path
else
echo -e "${GREEN}The path you entered is: $dinky_home_path${RESET}"
add_to_env "DINKY_HOME" "$dinky_home_path" "$ENV_FILE"
add_to_env "PATH" "\$DINKY_HOME/bin" "$ENV_FILE"
sleep 2
source $ENV_FILE
echo -e "${GREEN}DINKY_HOME environment variable configuration completed. Please confirm whether the following configuration is correct:${RESET}"
grep -E '^(export DINKY_HOME)' $ENV_FILE | grep -v "^#" | grep -v "^$"
fi
break
;;
3)
echo -e "${GREEN}Cancel configuration${RESET}"
break
;;
*)
echo -e "${RED}Invalid input, please re-run the script to select the correct option.${RESET}"
;;
esac
done
1 change: 1 addition & 0 deletions script/bin/init_flink_dependences.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -x

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

EXTENDS_HOME=$1

Expand Down Expand Up @@ -31,5 +32,3 @@ case $hadoop_uber_version in
echo -e "${RED}The entered version number is incorrect, please re-run the script to select the correct version.${RESET}"
;;
esac

echo -e "${GREEN}After the download is completed, subsequent installation and configuration operations can be performed as needed.${RESET}"
19 changes: 19 additions & 0 deletions script/bin/init_jdbc_driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -x

DINKY_LIB_DIR=$1

echo -e "${GREEN}Start downloading the mysql driver package...${RESET}"
if [ -f "${DINKY_LIB_DIR}/mysql-connector-j-8.4.0.jar" ]; then
echo -e "${YELLOW}mysql The driver package already exists, no need to download it again. Skip this step。${RESET}"
else
download_file https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.4.0/mysql-connector-j-8.4.0.jar "${DINKY_LIB}"
echo -e "${GREEN}Download is complete, please verify. The downloaded file storage address is: ${DINKY_LIB_DIR}/mysql-connector-j-8.4.0.jar${RESET}"
if [ -f "${DINKY_LIB_DIR}/mysql-connector-j-8.4.0.jar" ]; then
echo -e "${GREEN}mysql driver package downloaded successfully。${RESET}"
else
echo -e "${RED}Mysql driver package download failed, please check the network or download manually。${RESET}"
exit 1
fi
echo -e "${GREEN}After the verification is completed, subsequent installation and configuration operations can be performed as needed.。${RESET}"
fi
Loading

0 comments on commit a1613a1

Please sign in to comment.