devicesmgt/scripts/deploy.sh

66 lines
2.2 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
export deploy_path=/opt/webapps/NingXiaJiJu
#export jars_path = /home/jenkins/workspace/NingXiaJiJu/bonus-auth/target
export app_workspace=/home/jenkins/workspace/NingXiaJiJu
app_source_jars=(
"sgzb-api/sgzb-api-system/target/sgzb-api-system-3.6.3.jar"
"sgzb-auth/target/sgzb-auth.jar"
"sgzb-gateway/target/sgzb-gateway.jar"
"sgzb-modules/sgzb-base/target/sgzb-base.jar"
"sgzb-modules/sgzb-file/target/sgzb-file.jar"
"sgzb-modules/sgzb-gen/target/sgzb-gen.jar"
"sgzb-modules/sgzb-job/target/sgzb-job.jar"
"sgzb-modules/sgzb-material/target/sgzb-material.jar"
"sgzb-modules/sgzb-settlement/target/sgzb-settlement.jar"
"sgzb-modules/sgzb-system/target/sgzb-system.jar"
"sgzb-visual/target/sgzb-visual-monitor.jar"
)
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
jars=("sgzb-auth.jar" "sgzb-gateway.jar" "sgzb-modules-base.jar" "sgzb-modules-file.jar"
"sgzb-modules-gen.jar" "sgzb-modules-job.jar" "sgzb-modules-material.jar"
"sgzb-modules-settlement.jar" "sgzb-modules-system.jar" "sgzb-system.jar"
"sgzb-visual-monitor.jar" "sentinel-dashboard-1.8.1.jar")
# 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."