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启动脚本

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值