自动化部署脚本——杀进程,然后启动jar

#! /bin/bash

# 1.杀掉 ygb-promoting 进程
kill -9 $(netstat -nlp | grep :8383 | awk '{print $7}' | awk -F"/" '{print $1}')

# 2.进入目标目录
cd /data/ygb_promoting/jar

# 3.找到所有的.jar文件
j=0
for file in `ls /data/ygb_promoting/jar | grep .jar$`
do
    file_list[j]=$file
    j=`expr $j+1`
done

# 4.将这些.jar文件重命名为.jar.bak后缀
for file in ${file_list[@]}
do
    if [ ${file} ]
    then
        echo "$file was renamed by ${file}.bak"
        mv $file $file.bak
    fi
done

# 5.将最新版本的 ygb-promoting-xxx.jar 移动到当前路径,并启动。
mv /root/ygb_promoting/yin-guan-bao-promoting-**.jar /data/ygb_promoting/jar
latest_jar=$(ls | grep .jar$) # jar的文件全名
echo "Run $latest_jar now"
latest_version=$(awk 'BEGIN{print "'$latest_jar'"}' | awk -F"-" '{print $5}'  | awk -F".jar" '{print $1}') # jar文件的版本号
echo "The log file was stored into ../log/log.${latest_version}.out"
chmod u+x $latest_jar
nohup java -Xmx1g -Dspring.profiles.active=test-7-2 -jar $latest_jar >> ../log/log.${latest_version}.out 2>&1 &
echo "OK"

你可能感兴趣的:(自动化部署脚本——杀进程,然后启动jar)