lcfs/tools/deploy.sh

60 lines
1.7 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
killProcess(){
process_keyword=$1
pid=$(pgrep -f -d " " "${process_keyword}" )
if [ ! "" = "$pid" ]; then
echo "当前${process_keyword}进程为 $pid, 使用kill -15停止"
kill -15 $pid
for ((i=1; i<=15; i++));
do
if [ ! "" = "$pid" ]; then
sleep 1
fi
pid=$(pgrep -f "${process_keyword}" )
done
if [ ! "" = "$pid" ]; then
echo "15秒未成功强制杀死进程 $pid"
kill -9 $pid
fi
else
echo "未检测到${process_keyword}相关进程,无需停止"
fi
}
# 检测进程是否存活
checkProcess(){
process_keyword=$1
pid=$(pgrep -f "${process_keyword}" )
if [ ! "" = "$pid" ]; then
echo "当前${process_keyword}进程为 $pid"
else
echo "未检测到${process_keyword}相关进程,发布失败,请检查"
exit 1
fi
}
# rollBackupFiles 文件所在目录 文件全名 备份最大保留天数 。 如: rollBackupFiles /home/scfs/job sunbta-job.jar 10
rollBackupFiles(){
file_path=$1 # 路径
file_name=$2 # 文件名
preserve_day=$3 # 备份文件保留天数
echo "备份并删除${preserve_day}天前的备份"
cd "$file_path" || exit 255
find ~/app/service/ -mtime +"${preserve_day}" -name "${file_name}.*.bak" -exec rm -rf {} \;
mv "${file_name}" "${file_name}.$(date +%Y%m%d%H%M%S).bak"
cd - || exit 255
}
main(){
killProcess "${1}.jar"
rollBackupFiles ~/app/service/ ${1}.jar -1
mv ~/deploy/${1}/target/${1}.jar ~/app/service/
chmod +x ~/app/service/*
# nohup java -jar -Dfile.encoding=UTF-8 ~/app/service/${1}.jar >/dev/null 2>&1 &
# sleep 2
# checkProcess "${1}.jar"
}
main $1