• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Linux-启动停止重启-springboot-jar包-脚本

linux 搞代码 3年前 (2022-03-03) 22次浏览 已收录 0个评论
<code class="linux">
#!/bin/bash
#这里可替换为你本人的执行程序,其余代码无需更改
APP_NAME=asug.jar
WAR_LOCATION=../asug/target
BAK_LOCATION=warBak

#应用阐明,用来提醒输出参数
usage() {
    echo "Usage: sh 脚本名.sh [start|stop|restart|status|deploy]"
    exit 1
}

#检查程序是否在运行
is_exist(){
  pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
  #如果不存在返回1,存在返回0
  if [ -z "${pid}" ]; then
   return 1
  else
    return 0
  fi
}
#启动办法
start(){
  is_exist
  if [ $? -eq "0" ]; then
    echo "${APP_NAME} is already running. pid=${pid} ."
  else
    nohup java  -jar ./${APP_NAME} --server.port=8080 --spring.profiles.active=prod > /dev/null 2>&1 &
  fi
}

#进行办法
stop(){
  is_exist
  if [ $? -eq "0" ]; then
    kill -9 $pid
  else
    echo "${APP_NAME} is not running"
  fi
}

#输入运行状态
status(){
  is_exist
  if [ $? -eq "0" ]; then
    echo "${APP_NAME} is running. Pid is ${pid}"
  else
    echo "${APP_NAME} is NOT running."
  fi
}

#重启
restart(){
  stop
  start
}

deploy(){
  stop
  cp $APP_NAME $BAK_LOCATION/$APP_NAME.$(date "+%Y%m%d%H%M")
  rm -rf $APP_NAME
  rm -rf nohup.out
  cp $WAR_LOCATION/$APP_NAME $APP_NAME
  start
}

#依据输出参数,抉择执行对应办法,不输出则执行应用阐明
case "$1" in
  "start")
    start
    ;;
  "stop")
    stop
    ;;
  "status")
    status
    ;;
  "restart")
    restart
    ;;
  "deploy")
    deploy
    ;;
  *)
    usage
    ;;
esac

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Linux-启动停止重启-springboot-jar包-脚本
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址