SpringBoot導入スクリプトの起動


説明
Springbootエンジニアリング起動スクリプト、記録してください.
スクリプト・インスタンス
#!/bin/sh
#
# Copyright (c) 2019 by lulongij.
# All rights reserved.
#
#ident  "@(#)Connectorlication 2.0"

#  jar  
APP_NAME=test

#JDK  
#JAVA_HOME=/app/java/jdk8

#  debug       
APP_DEBUGE=
#APP_DEBUGE="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=18894"

#JVM  
JVM_OPTS='-Xms1024m -Xmx1024m -XX:MaxPermSize=256m -XX:NewRatio=4 -XX:+UseParallelGC -XX:ParallelGCThreads=8 -XX:+UseAdaptiveSizePolicy -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:-HeapDumpOnOutOfMemoryError -Xloggc:verbose-gc-sp.txt'


#      jdk     
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
    javaexe="$JAVA_HOME/bin/java"
elif type -p java > /dev/null 2>&1; then
    javaexe=$(type -p java)
elif [[ -x "/usr/bin/java" ]];  then
    javaexe="/usr/bin/java"
else
    echo "Unable to find Java"
    exit 1
fi

#        
SOURCE="$0"
while [ -h "$SOURCE"  ]; do
    DIR="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    [[ $SOURCE != /*  ]] && SOURCE="$DIR/$SOURCE"
done
WORKING_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"

#    
APP_HOME="$(dirname "$WORKING_DIR")"

#        
APP_CONF="$APP_HOME/conf/application.properties"

#    
LOG_FILE="--logging.config=$APP_HOME/conf/logback.xml"

JAR_FILE=$APP_HOME/lib/$APP_NAME*.jar

pid=00000
#    
APP_PID=$APP_HOME/$APP_NAME.pid

APP_CONF="--spring.config.location=file:$APP_CONF"

start(){
 checkpid
 if [ $? -eq 0 ]; then
    echo JDK  : $JAVA_HOME
    echo     : $APP_HOME
    echo     : $APP_NAME
    echo     : $APP_CONF
    echo JVM  : $JAVA_OPTS

    if  [ ! -n "$APP_DEBUGE" ] ;then
        echo "  debug  !"
    else
        echo "  debug  !"
    fi

    /bin/sh -c  "$javaexe -jar $APP_DEBUGE $JVM_OPTS $JAR_FILE $APP_CONF  $LOG_FILE > /dev/null 2>&1 & echo \$!" > "$APP_PID"
    echo "---------------------------------"
    echo "    "
    echo "---------------------------------"
    sleep 2s
  else
      echo "$APP_NAME is runing PID: $pid"
  fi

}

status(){
   checkpid
   if [ $? -eq 0 ]; then
     echo  "$APP_NAME not runing"
   else
     echo "$APP_NAME runing PID: $pid"
   fi
}


checkpid(){
   if [[ -f "$APP_PID" ]]; then
        pid=$(cat "$APP_PID")
        PIDNUM=`ps -ef |grep "$pid" -i |grep -v grep |wc -l`
        if [ $PIDNUM -eq 0 ];then
        return 0;
        else
                return 1;
        fi
   else
        return 0;
   fi
}


stop(){
    checkpid
    if [ $? -eq 0 ]; then
      echo "$APP_NAME not runing"
    else
      echo "$APP_NAME stop..."
      kill -9 $pid
    fi
}

restart(){
    stop
    sleep 1s
    start
}

case $1 in
          start) start;;
          stop)  stop;;
          restart)  restart;;
          status)  status;;
              *)  echo "require start|stop|restart|status"  ;;
esac

説明
本文はただ学習の参考だけをして、もし何か不正確なところがあれば指摘を歓迎します.