#!/bin/bash
printf "备份上一版本的包 \n"
jarName=forwe-bp.jar
fileDate=`ls --full-time ${jarName} | cut -d ' ' -f 6`
fileTime=`ls --full-time ${jarName} | cut -d ' ' -f 7`
fileName=${jarName}.${fileDate}_${fileTime}
echo ${fileName}
if [[ ! -d "old_package" ]]; then
mkdir "old_package"
fi
mv ${jarName} old_package/${fileName}

printf "拷贝新版本的包 \n"
cp upload/${jarName} ${jarName}

printf "准备停止服务\n" 
source stop.sh

printf "准备启动服务\n"
j=''
for ((i=0;$i<=100;i+=2))
do
        printf "准备中:[%-50s]%d%%\r" $j $i
        sleep 0.1
        j=#$j
done
printf "\n"
#判断服务进程是否存在
pid=$(ps -ef | grep ${jarName} | grep -v grep | awk '{ print $2 }')
if [[ ! -z "$pid" ]];
then
    echo -e "\033[31m准备失败，服务运行中\033[0m"
    exit 1 
fi   
source start.sh	
