Bonus-Cloud/scripts/deploy.sh

65 lines
2.1 KiB
Bash
Raw Normal View History

2024-07-09 08:48:51 +08:00
#!/bin/bash
export deploy_path=/opt/webapps/bonus-cloud
export app_workspace=/home/jenkins/workspace/Bonus-Cloud
app_source_jars=(
"bonus-auth/target/bonus-auth.jar"
"bonus-gateway/target/bonus-gateway.jar"
"bonus-modules/bonus-file/target/bonus-file.jar"
"bonus-modules/bonus-gen/target/bonus-gen.jar"
"bonus-modules/bonus-job/target/bonus-job.jar"
"bonus-modules/bonus-oss/target/bonus-oss.jar"
"bonus-modules/bonus-system/target/bonus-system.jar"
2024-07-24 10:31:06 +08:00
"bonus-visual/bonus-monitor/target/bonus-visual-monitor.jar"
2024-07-09 08:48:51 +08:00
)
for source_jar in "${app_source_jars[@]}"; do
cp -f ${app_workspace}/${source_jar} $deploy_path
2024-07-24 10:31:06 +08:00
echo "copied ${app_workspace}/${source_jar} to $deploy_path"
2024-07-09 08:48:51 +08:00
done
# Define an array of JAR files to run
2024-07-23 16:09:59 +08:00
jars=("bonus-auth.jar --spring.config.location=file:auth_bootstrap.yml"
"bonus-gateway.jar --spring.config.location=file:gateway_bootstrap.yml"
"bonus-system.jar --spring.config.location=file:system_bootstrap.yml"
2024-07-24 10:31:06 +08:00
"bonus-gen.jar --spring.config.location=file:gen_bootstrap.yml"
"bonus-job.jar --spring.config.location=file:job_bootstrap.yml"
2024-07-23 16:09:59 +08:00
"bonus-file.jar --spring.config.location=file:file_bootstrap.yml"
"bonus-visual-monitor.jar --spring.config.location=file:visual_bootstrap.yml")
2024-07-09 08:48:51 +08:00
2024-07-24 10:31:06 +08:00
# 遍历数组并检查每个JAR文件的进程
for jar_with_args in "${jars[@]}"; do
# 提取JAR文件名不包括参数
jar=$(echo $jar_with_args | awk '{print $1}')
2024-07-09 08:48:51 +08:00
2024-07-24 10:31:06 +08:00
# 检查进程是否启动
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"
2024-07-09 08:48:51 +08:00
fi
done
# Iterate over the JAR files array
for jar in "${jars[@]}"; do
2024-07-24 10:31:06 +08:00
echo "Starting $jar"
nohup java -jar $jar >/dev/null 2>&1 &
2024-07-09 08:48:51 +08:00
done
echo "All JARs have been run successfully."
2024-07-24 10:31:06 +08:00