Linux使用Shell脚本控制Tomcat/SpringBoot2(war,jar)启动关闭

时间:2020-03-31 14:21:12   收藏:0   阅读:142

#!/bin/bash为必加项
保存为tom.sh 执行sh tom.sh启动

TOMCAT启动与关闭快捷shell脚本

 #!/bin/bash
 #To quickly start tomcat or shutdown.
 #by ukyozq 
 #lastChangeTime:2018-1-21 9:12

#tomcat bin path short as tbp.
 tbp=/usr/local/tomcat/apache-tomcat-9.0.11/bin

 #the command $1 match 1 to start, match 0 to stop.
 cmd=$1

 #Logic shell code follow.
 if [[ -z $cmd ]];then
     echo "err!usage{sh $0 1|0 to start or shutdown.}"
 elif [[ $cmd -eq 1 ]];then
     sh $tbp/startup.sh
 elif [[ $cmd -eq 0 ]];then
     sh $tbp/shutdown.sh
 else
     echo "err!just 1 or 0 behind $0,like(sh $0 1)"
 fi

 #$? to test the .sh stat.
 if [[ $? -eq 0 ]];then
     echo -e "\033[32mtom.sh run succeed. \033[0m"
 else
     echo -e "\033[32mtom.sh run failed,check the code involved.\033[0m"
 fi

 

部署SpringBoot(jar,war)项目的shell脚本(持久运行)
保存为startSpring.sh 执行sh startSpring.sh启动

#!/bin/sh
RESOURCE_NAME=newindex-0.0.1-SNAPSHOT.war
cmd=$1

tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk ‘{print $2}‘`


if [[ -z $cmd ]];then
     echo ‘err,usage{ sh $0 1|0 to start or stop jar}‘
elif [[ $cmd -eq 1 ]];then
     nohup java -jar /usr/local/springboot2.0_jar/$RESOURCE_NAME --spring.profiles.active=test &
     echo $! > tpid
      echo ‘Start Success!~~~‘
elif [[ $cmd -eq 0 ]];then
      echo ‘Stop Process...‘
      kill -15 $tpid
      sleep 5
      echo ‘Kill Process!‘
      kill -9 $tpid
      echo ‘Stop Success!else 
      echo ‘err!just 1 or 0 behind $0, like (sh $0 1)‘
fi   

 

 

原文:https://www.cnblogs.com/ukzq/p/12604861.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!