Bonus-Cloud/scripts/deploy.sh

66 lines
2.2 KiB
Bash
Raw Normal View History

2024-07-09 08:48:51 +08:00
#!/bin/bash
export deploy_path=/opt/webapps/bonus-cloud
#export jars_path = /home/jenkins/workspace/Bonus-Cloud/bonus-auth/target
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-16 19:21:50 +08:00
"bonus-visual/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
echo "copied ${app_workspace}/${source_jar}/auth/target/auth.jar to $deploy_path"
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"
"bonus-gen.jar --spring.config.location=file:gen_bootstrap.ym"
"bonus-job.jar --spring.config.location=file:job_bootstrap.ym"
"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
# Stop all running JARs
for jar in "${jars[@]}"; do
P_ID=$(pgrep -f "$jar")
# 如果该项目已经在服务器上启动则kill掉
echo "原应用程序$jar进程id$P_ID"
if [ -z "$P_ID" ]; then
echo "==$jar service process does not exist"
else
# 尝试优雅地关闭应用程序
kill -9 "$P_ID"
wait "$P_ID" 2>/dev/null
# 检查进程是否仍在运行
if ! ps -p "$P_ID" > /dev/null; then
echo "$jar service process was terminated gracefully"
else
# 如果优雅关闭失败,则强制杀死进程
kill -9 "$P_ID"
echo "$jar service process was killed forcefully"
fi
fi
done
# Iterate over the JAR files array
for jar in "${jars[@]}"; do
echo "Running $jar..."
# Assuming java is in your PATH and the JARs are in the current directory
nohup /usr/lib/jvm/jdk1.8.0_381/bin/java -jar "$jar" >/dev/null 2>&1 &
done
echo "All JARs have been run successfully."