Bonus-Cloud-Houqin/scripts_244_bonus_houqin_test/deploy.sh

84 lines
3.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
suffix="-smart-canteen"
jar_version="24.10.0-SNAPSHOT"
export deploy_path=/opt/webapps/bonus-houqin
export app_workspace=/opt/builds/releases/Bonus-Cloud/${jar_version}
export biz_workspace=/opt/install/jenkins_home/workspace/Bonus-Cloud-Smart-Canteen
app_source_jars=(
"bonus-auth-${jar_version}.jar"
"bonus-gateway-${jar_version}.jar"
"bonus-system-${jar_version}.jar"
"bonus-job-${jar_version}.jar"
"bonus-file-${jar_version}.jar"
"bonus-visual-monitor-${jar_version}.jar"
)
#for source_jar in "${app_source_jars[@]}"; do
# cp -f ${app_workspace}/${source_jar} $deploy_path
# echo "copied ${app_workspace}/${source_jar} to $deploy_path"
#done
for source_jar in "${app_source_jars[@]}"; do
# 获取文件名(不带目录路径)
filename=$(basename "$source_jar")
echo "filename:$filename"
# 获取文件名(不带扩展名)
base_name="${filename%.jar}"
echo "filename:$base_name"
# 构造新的文件名
new_filename="${base_name}${suffix}.jar"
echo "filename:$new_filename"
cp -f ${app_workspace}/${source_jar} "$deploy_path/$new_filename"
echo "copied ${app_workspace}/${source_jar} to '$deploy_path/$new_filename'"
done
cp -f ${biz_workspace}/"bonus-modules/bonus-smart-canteen/target/bonus-smart-canteen.jar" $deploy_path
echo "copied ${app_workspace}/${source_jar} to $deploy_path"
# Define an array of JAR files to run
jars=("bonus-auth-${jar_version}-smart-canteen.jar --spring.config.location=file:auth_bootstrap.yml"
"bonus-gateway-${jar_version}-smart-canteen.jar --spring.config.location=file:gateway_bootstrap.yml"
"bonus-system-${jar_version}-smart-canteen.jar --spring.config.location=file:system_bootstrap.yml"
"bonus-job-${jar_version}-smart-canteen.jar --spring.config.location=file:job_bootstrap.yml"
"bonus-file-${jar_version}-smart-canteen.jar --spring.config.location=file:file_bootstrap.yml"
"bonus-visual-monitor-${jar_version}-smart-canteen.jar --spring.config.location=file:visual_bootstrap.yml"
"bonus-smart-canteen.jar --spring.config.location=file:smart_canteen_bootstrap.yml"
"bonus-cust-auth.jar --spring.config.location=file:cust_auth_bootstrap.yml")
# 遍历数组并检查每个JAR文件的进程
for jar_with_args in "${jars[@]}"; do
# 提取JAR文件名不包括参数
jar=$(echo $jar_with_args | awk '{print $1}')
# 检查进程是否启动
echo "原应用程序1 $jar "
pids=$(pgrep -f $jar || true)
echo "原应用程序2 $jar "
if [ -n "$pids" ]; then
echo "$jar is running with PID(s): $pids"
# 杀死进程
for pid in $pids; do
kill -9 $pid
if [ $? -eq 0 ]; then
echo "Process $pid for $jar killed successfully"
else
echo "Failed to kill process $pid for $jar"
fi
done
else
echo "$jar is not running"
fi
done
cd $deploy_path || { echo "Failed to change directory to $deploy_path"; exit 1; }
# Iterate over the JAR files array
for jar in "${jars[@]}"; do
echo "Starting $jar"
nohup /usr/local/jdk1.8.0/bin/java -jar $jar >/dev/null 2>&1 &
done
echo "All JARs have been run successfully."