通用spring boot jar包,服務重啓停腳本分享

需根據實際狀況設置JAVA_HOME、APP_HOME
腳本使用方式:bash restart.sh {start|stop|restart|status|info}
vi restart.shjava

#!/bin/bash
source /etc/profile
JAVA_HOME=/usr/local/jdk1.8.0_152
# application directory
cd `dirname $0`
#APP_HOME=`pwd`
APP_HOME="/appsystems/new-cts/cts-epp"
APP_NAME="`cd ${APP_HOME} && find -name '*.jar' `"
JAR_HOME=`${APP_HOME} |awk -F"/" '{print $NF}'`
# Java JVM lunch parameters
if [ x"$JVMSIZE" == x ];then
  JVMSIZE="-Xms1G -Xmx1G -Djava.security.egd=file:/dev/./urandom"
fi
# waiting timeout for starting, in seconds
START_WAIT_TIMEOUT=30
psid=0
checkpid() {
  javaps=`$JAVA_HOME/bin/jps -l | grep "$JAR_HOME"`
  if [ -n "$javaps" ]; then
   psid=`echo $javaps | awk '{print $1}'`
  else
   psid=0
  fi
}
start() {
  checkpid
  if [ $psid -ne 0 ]; then
   echo "================================"
   echo "warn: $APP_NAME already started! (pid=$psid)"
   echo "================================"
  else
   echo -n "Starting $APP_NAME ..."
   $JAVA_HOME/bin/java ${JVMSIZE} ${EUREKA} ${LOGPATH} ${APM} ${APOLLO} -jar ${APP_NAME} >/dev/null 2>&1 &  
   checkpid
   if [ $psid -ne 0 ]; then
     echo "(pid=$psid) [OK]"
   else
     echo "[Failed]"
   fi
  fi
}
stop() {
  sleep 2
  checkpid
  if [ $psid -ne 0 ]; then
   echo -n "Stopping $APP_NAME ...(pid=$psid) "
   kill -9 $psid
   if [ $? -eq 0 ]; then
     echo "[OK]"
   else
     echo "[Failed]"
   fi
# checkpid
# if [ $psid -ne 0 ]; then
# stop
# fi
  else
   echo "================================"
   echo "warn: $APP_NAME is not running"
   echo "================================"
  fi
}
status() {
  checkpid
  if [ $psid -ne 0 ]; then
   echo "$APP_NAME is running! (pid=$psid)"
  else
   echo "$APP_NAME is not running"
  fi
}
info() {
  echo "System Information:"
  echo "****************************"
  echo `head -n 1 /etc/issue`
  echo `uname -a`
  echo
  echo "JAVA_HOME=$JAVA_HOME"
  echo `$JAVA_HOME/bin/java -version`
  echo
  echo "APP_HOME=$APP_HOME"
  echo "APP_NAME=$APP_NAME"
  echo "****************************"
}
case "$1" in
  'start')
   start
   ;;
  'stop')
   stop
   ;;
  'restart')
   stop
   echo "You restart the application ..."
   start
   ;;
  'status')
   status
   ;;
  'info')
   info
   ;;
 *)
   echo "Usage: $0 {start|stop|restart|status|info}"
   exit 1
esac
相關文章
相關標籤/搜索