Skip to content

Commit 8d7a37e

Browse files
committed
[Optimization-4068] Optimize the execution logic of the script
1 parent 0481223 commit 8d7a37e

File tree

4 files changed

+57
-38
lines changed

4 files changed

+57
-38
lines changed

script/bin/auto.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ function wait_start_process() {
140140
for code in "${success_status_codes[@]}"; do
141141
if [ "$health_status" == "$code" ]; then
142142
echo -ne "\r[==================================================] 100%\n"
143-
echo -e "${GREEN}Application started completed.${RESET}"
144143
return 0
145144
fi
146145
done
@@ -149,11 +148,11 @@ function wait_start_process() {
149148
local filled_length=$((progress * bar_length / 100))
150149
local empty_length=$((bar_length - filled_length))
151150
local bar=$(printf '>%.0s' $(seq 1 $filled_length))$(printf ' %.0s' $(seq 1 $empty_length))
152-
echo -ne "\r[${bar}] ${progress}% (time consuming: ${formatted_time})"
151+
local processing_inline="\r[${bar}] ${progress}% (time consuming: ${formatted_time})"
152+
echo -ne "${processing_inline}"
153153
sleep $delay
154154
done
155-
echo -ne "\r[==================================================] 100% (time consuming: ${formatted_time})\n"
156-
echo -e "${RED}Application start failed. Please check the log for details.${RESET}"
155+
echo -ne "${processing_inline}\n"
157156
return 1
158157
}
159158

@@ -218,7 +217,10 @@ start() {
218217
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 &
219218
PID=$!
220219
echo "${PID}" >"${PID_PATH}"/${PID_FILE}
221-
wait_start_process
220+
if ! wait_start_process; then
221+
echo -e "${RED}Application start failed. Please check the log for details. you can execute tail -fn1000 ${DINKY_LOG_PATH}/dinky-start.log to watch the log ${RESET}"
222+
exit 1
223+
fi
222224
echo -e "${GREEN}........................................Start Dinky Successfully........................................${RESET}"
223225
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}"
224226
else
@@ -243,7 +245,10 @@ startWithJmx() {
243245
if [ -z "$pid" ]; then
244246
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 &
245247
PID=$!
246-
wait_start_process
248+
if ! wait_start_process; then
249+
echo -e "${RED}Application start failed. Please check the log for details. you can execute tail -fn1000 ${DINKY_LOG_PATH}/dinky-start.log to watch the log ${RESET}"
250+
exit 1
251+
fi
247252
echo -e "$GREEN........................................Start Dinky with Jmx Successfully........................................$RESET"
248253
updatePid
249254

script/bin/init_flink_dependences.sh

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,37 @@ if [ -f "${FLINK_STORE_DIR}/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.t
2828
fi
2929
fi
3030

31-
try_tsinghua_mirror() {
31+
try_mirrors_download_file() {
3232
local tsinghua_url="https://mirrors.tuna.tsinghua.edu.cn/apache/flink/flink-${CURRENT_FLINK_FULL_VERSION}/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz"
33+
local aliyun_url="https://mirrors.aliyun.com/apache/flink/flink-${CURRENT_FLINK_FULL_VERSION}/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz"
3334
local apache_url="https://archive.apache.org/dist/flink/flink-${CURRENT_FLINK_FULL_VERSION}/flink-${CURRENT_FLINK_FULL_VERSION}-bin-scala_2.12.tgz"
34-
3535
echo -e "${GREEN}Start downloading the Flink-${FLINK_VERSION_SCAN} installation package... Store it in the ${FLINK_STORE_DIR} directory${RESET}"
36-
if download_file "$tsinghua_url" "${FLINK_STORE_DIR}"; then
37-
echo -e "${BLUE}The address of the currently downloaded Flink installation package is:${tsinghua_url}${RESET}"
36+
exec_tsinghua_result=$(download_file "$tsinghua_url" "${FLINK_STORE_DIR}")
37+
if [ ! "$exec_tsinghua_result" ]; then
38+
echo -e "${BLUE}The tsinghua address of the currently downloaded Flink installation package is:${tsinghua_url}${RESET}"
3839
return 0
3940
else
40-
echo -e "${YELLOW}File not found in Tsinghua University mirror, try downloading from Apache official source...${RESET}"
41-
if download_file "$apache_url" "${FLINK_STORE_DIR}"; then
42-
echo -e "${BLUE}The address of the currently downloaded Flink installation package is:${apache_url}${RESET}"
41+
echo -e "${YELLOW}Failed to download from Tsinghua mirror, try downloading from Aliyun mirror...${RESET}"
42+
exec_aliyun_result=$(download_file "$aliyun_url" "${FLINK_STORE_DIR}")
43+
if [ "$exec_aliyun_result" ]; then
44+
echo -e "${BLUE}The aliyun address of the currently downloaded Flink installation package is:${aliyun_url}${RESET}"
4345
return 0
4446
else
45-
echo -e "${RED}Downloading from Apache official source also failed, please check the network or download manually。${RESET}"
46-
return 1
47+
echo -e "${YELLOW}Failed to download from Aliyun mirror too, try downloading from Apache official source...${RESET}"
48+
49+
exec_apache_result=$(download_file "$apache_url" "${FLINK_STORE_DIR}")
50+
if [ "$exec_apache_result" ]; then
51+
echo -e "${RED}Downloading from Apache official source also failed, please check the network or download manually。${RESET}"
52+
return 1
53+
else
54+
echo -e "${BLUE}The apache address of the currently downloaded Flink installation package is:${apache_url}${RESET}"
55+
return 0
56+
fi
4757
fi
4858
fi
4959
}
5060

51-
if ! try_tsinghua_mirror; then
61+
if ! try_mirrors_download_file; then
5262
exit 0
5363
fi
5464

@@ -100,6 +110,10 @@ echo -e "${GREEN}Process flink-state-processor-api ...${RESET}"
100110
cp -r ${full_flink_dir_tmp}/opt/flink-state-processor-api*.jar ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/
101111
echo -e "${GREEN}Processing completed。${RESET}"
102112

113+
echo -e "${GREEN}Process flink-s3-fs-presto ...${RESET}"
114+
cp -r ${full_flink_dir_tmp}/opt/flink-s3-fs-presto*.jar ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/
115+
echo -e "${GREEN}Processing completed。${RESET}"
116+
103117
echo -e "${GREEN} ================= List files in the ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/ directory ==============${RESET}"
104118
ls -l ${EXTENDS_HOME}/flink${FLINK_VERSION_SCAN}/
105119

script/bin/init_jdbc_driver.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
DINKY_LIB_DIR=$1
44

55
echo -e "${GREEN}Start downloading the mysql driver package...${RESET}"
6-
if [ -f "${DINKY_LIB_DIR}/mysql-connector-j-8.4.0.jar" ]; then
7-
echo -e "${YELLOW}mysql The driver package already exists, no need to download it again. Skip this step。${RESET}"
6+
# Run the command to check whether the file exists
7+
exec_result=$(ll "${DINKY_LIB_DIR}"/mysql-connector-j-8.4.0.jar)
8+
if [ "$exec_result" ]; then
9+
echo -e "${YELLOW}The mysql driver package already exists, no need to download it again. Skip this step. ${RESET}"
810
else
911
download_file https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.4.0/mysql-connector-j-8.4.0.jar "${DINKY_LIB_DIR}"
10-
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}"
12+
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}"
1113
if [ -f "${DINKY_LIB_DIR}/mysql-connector-j-8.4.0.jar" ]; then
12-
echo -e "${GREEN}mysql driver package downloaded successfully${RESET}"
14+
echo -e "${GREEN}mysql driver package downloaded successfully. ${RESET}"
1315
else
14-
echo -e "${RED}Mysql driver package download failed, please check the network or download manually${RESET}"
16+
echo -e "${RED}Mysql driver package download failed, please check the network or download manually. ${RESET}"
1517
exit 1
1618
fi
17-
echo -e "${GREEN}After the verification is completed, subsequent installation and configuration operations can be performed as needed.${RESET}"
19+
echo -e "${GREEN}After the verification is completed, subsequent installation and configuration operations can be performed as needed. ${RESET}"
1820
fi

script/bin/init_tools_main.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,17 @@ function get_home_path() {
5151
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
5252
done
5353
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
54-
RETURN_HOME_PATH=$(dirname "$DIR")
55-
}
56-
57-
58-
59-
if [ -z "${DINKY_HOME}" ]; then
60-
echo -e "${RED}DINKY_HOME environment variable is not set. Attempting to determine the correct path...${RESET}"
61-
get_home_path
62-
APP_HOME="${RETURN_HOME_PATH}"
63-
else
64-
get_home_path
65-
if [ "${DINKY_HOME}" != "${RETURN_HOME_PATH}" ]; then
66-
echo -e "${YELLOW}DINKY_HOME is not equal to the current path, use new path to init: ${RETURN_HOME_PATH}${RESET}"
67-
APP_HOME="${RETURN_HOME_PATH}"
54+
local possible_path=$(dirname "$DIR")
55+
if [ -d "$possible_path" ]; then # Verify that the path obtained is a directory, increasing robustness
56+
RETURN_HOME_PATH="$possible_path"
6857
else
69-
echo -e "${GREEN}DINKY_HOME is already set to: ${DINKY_HOME}${RESET}"
58+
echo -e "${RED}Calculated path $possible_path is not a valid directory. Please check the script location or deployment setup.${RESET}"
59+
exit 1
7060
fi
71-
fi
61+
}
62+
63+
get_home_path
64+
APP_HOME="${RETURN_HOME_PATH}"
7265

7366
echo -e "${GREEN}Dinky root path: ${APP_HOME} ${RESET}"
7467

@@ -131,7 +124,12 @@ function download_file() {
131124
target_file_dir=$2
132125
echo -e "${GREEN}Start downloading $source_url to $target_file_dir...${RESET}"
133126
wget -P "${target_file_dir}" "${source_url}"
127+
if [ $? -ne 0 ]; then
128+
echo -e "${RED}Failed to download $source_url to $target_file_dir. Please check the network connection and try again.${RESET}"
129+
return 1
130+
fi
134131
echo -e "${GREEN}Download completed. The downloaded file storage address is: $target_file_dir ${RESET}"
132+
return 0
135133
}
136134

137135
export -f download_file

0 commit comments

Comments
 (0)