springboot jar启动脚本

#!/bin/bash
#检查端口是否被占用,如果占用不能重复启动应用
port=8080
APP_NAME=appname-0.0.1-SNAPSHOT
pIDa=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
clientIp=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
#echo $pIDa
if [ "$pIDa" != "" ];
then
   echo "端口 ""$port"" 已被进程 ""$pIDa"" 占用,请勿重复启动应用!"
   exit 0
else
   nohup java -jar -Dserver.port=$port -DclientIp=$clientIp $APP_NAME".jar" --spring.profiles.active=dev >/dev/null 2>&1 &
fi

declare -i counter=0
declare -i max_counter=48 # 48*5=240s
declare -i total_time=0

printf "应用启动中"
until [[ (( counter -ge max_counter )) || `/usr/sbin/lsof -i :$port|grep -v "PID" | awk '{print $2}'` != "" ]];
do
    printf "."
    counter+=1
    sleep 5

done

total_time=counter*5

if [[ (( counter -ge max_counter )) ]];
then
    printf "\n`date '+%Y-%m-%d %H:%M:%S'` 应用启动累计耗时超过 $total_time 秒,启动失败!\n"
    exit 1;
fi

printf "\n`date '+%Y-%m-%d %H:%M:%S'` 应用启动完成,本次启动耗时 $total_time 秒!\n"

exit 0;

总结一个springboot项目jar启动脚本

你可能感兴趣的:(web)