栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

linux springboot 项目启动脚本

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux springboot 项目启动脚本

#!/bin/bash
# define color to echo
DEFAULT="33[0m"
RED="33[31m"
GREEN="33[32m"
YELLOW="33[33m"
BLUE="33[34m"
PURPLE="33[35m"
BLINK="33[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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1010536.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号