如何利用shell脚本操作spring boot 项目

本篇内容主要讲解“如何利用shell脚本操作spring boot 项目”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何利用shell脚本操作spring boot 项目”吧!


#利用脚本启动| 暂停|查看状态|重新启动 spring boot 项目#!/bin/bash#全局变量定义:
APP_NAME=springboot_demo
#函数定义:
Usage(){
 echo “Usage: sh 执行脚本”.sh [start|stop|restart|status]
 exit 1
}
#$? 是一个特殊变量,用来获取上一个命令的退出状态,或者上一个函数的返回值。
start(){
Is_exist   # 函数调用 直接写函数名称
If [ $? -eq “0” ];
then echo “$APP_NAME} is already running .pid=${pid}”
else
  nohup java -jar $APP_NAME >/dev/null 2>&1 &  # 后台启动Java程序
fi # 函数结尾
}

Is_exist(){
 pid=ps -ef |grep $APP_NAME
 If [ -z ‘$pid’ ]; then # 如果Pid 长度为0
  return 1 # 不存在返回1
 else
  Return 0
fi
}stop(){
 Is_exist   # 函数调用 直接写函数名称
 If[ $? eq 1 ]; then #如果不存在
  echo  “$APP_name  is not running “
 else
  Kill -9 $pid
}
 restart(){
 stop
 start
}

status(){
  Is_existIf[ $? eq “1”]; then # 不存在
  echo “$APP_NAME is not running”
else
  echo “$APP_NAME is running pid is $pid”
}


到此,相信大家对“如何利用shell脚本操作spring boot 项目”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!