linux springboot 项目启动脚本

#!/bin/bash
# define color to echo
DEFAULT="\033[0m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
PURPLE="\033[35m"
BLINK="\033[33;05m"
#the application program name u can change to yours' app name
SERVICE_NAME="ShellTest"

#the application program version u can change to yours' app version
SERVICE_VERSION="1.0-SNAPSHOT"

#the complete app name u can also just change here 
APP_NAME="${SERVICE_NAME}-${SERVICE_VERSION}.jar"

#this shell script name
FILE_SELF=`basename ${BASH_SOURCE}`

#introduct the usage of this shell script 
usage(){
 echo -e "${RED} -------------------------------------------------------------------------------------------------- "
 echo -e "${RED}|                                                                                                  |"
 echo -e "${RED}|${DEFAULT} u can use ${RED} sh ${FILE_SELF} start ${DEFAULT} to start ${APP_NAME}"
 echo -e "${RED}|${DEFAULT} the valid suffixes ${GREEN} start stop restart status${PURPLE}(view the app status)"
 echo -e "${RED}|                                                                                                  |"
 echo -e "${RED} -------------------------------------------------------------------------------------------------- ${DEFAULT}"
}

#judge the application program wheather launched
is_app_launched(){

 PID=`ps -ef |grep ${APP_NAME} |grep -v "grep" |awk '{print $2}'`
 if [ -n "${PID}" ]
  then
   #echo "the applicaiton program [${APP_NAME}] is launched and the pid is ${PID}"
   return 0;
 else
   #echo "the application program [${APP_NAME}] is not launched !"
   return 1; 
 fi

}

# view the status of the application program
status(){
 is_app_launched
 if [ $? -eq 0 ]
  then 
   echo -e "the application program ${RED} ${APP_NAME}${DEFAULT} is launched and pid is ${PID}"
 else
  echo -e "the application program ${RED}${APP_NAME}${DEFAULT} is not launched"
 fi
}

#stop the application program
stop(){
 is_app_launched
 if [ $? -eq 1 ] 
  then
   echo -e "${RED}[ FAIL ]--------stop failed because the application program is not launched ${DEFAULT}"
 else
  sudo kill -9 "${PID}"
  if [ $? -eq 1 ]
   then
    echo -e "${RED}[ FAIL ]--------stop failed unknow reason ${DEFAULT}"
  else
   echo -e "${GREEN}[ OK ]--------stop successfully ${DEFAULT}"
  fi 
 fi
}

#start the application program
start(){
 is_app_launched
 if [ $? -eq 0 ]
  then
   echo -e "${RED}[ FAIL ]--------start failed because the application program is launched ${DEFAULT}"
 else
  #here is the simplest command to launch the application program , u can change to yours' command
  nohup java -jar ./java/${APP_NAME} > /dev/null 2>&1 &
  if [ $? -eq 0 ]
   then 
    echo -e "${GREEN}[ OK ]--------start successfully ${DEFAULT}"
  else
    echo -e "${RED}[ FAIL ]--------start failed unknow reason ${DEFAULT}"
  fi
 fi
}

#restart the application program
restart(){
 is_app_launched
 if [ $? -eq 0 ]
  then  
   stop
   echo -e "${BLINK}It's begining to start up th application program...${DEFAULT}"
   sleep 3
   start
 else
   start
 fi
}

#u can select different options 
case "$1" in 
 "stop") stop
 ;; 
 "start") start
 ;;
 "restart") restart
 ;;
 "status") status
 ;;
 *) usage #default show the usage of this shell script
 ;; 
esac

linux springboot 项目启动脚本_第1张图片

你可能感兴趣的:(springboot,linux,linux,spring,boot,java)