Spring boot start.sh

脚本需要与springboot jar在同级目录。

#!/bin/bash

### stop function
### $1: pid.
function stop {
  kill -15 $1
}

# function run jar
## $1 jar file name
function runJars {
  nohup $JAVA_HOME/bin/java -jar $1 >/dev/null &
}

#  Restart function
#  $1: Jar file name
function reStart {
  jarFileName=$(ls -l|grep $1 | awk '{print$9}')
  pid=$(pgrep -f $jarFileName | awk '{print$1}')
  echo "***************$1********************"
  if [ ! -n "$pid" ]; then
      echo "$jarFileName is not started yet. Start now!"
      runJars $jarFileName
      echo "*************************************************"
  else
      echo "$jarFileName is running!(pid: $pid). Kill (with '-15 ')now!"
      stop $pid
      if [ $? -eq 0 ];then
          echo "kill $1 success! Try to start now!"
          runJars $jarFileName
          echo "*************************************************"
      else
          echo "Error: kill $1 process failed. PID: $pid"
      fi
  fi
}
#部分无需修改
# 修改这里的web修改成你的jar包的名称(没必要全写)
reStart "web"

你可能感兴趣的:(Spring boot start.sh)