Tomcat启停脚本
公司线上脚本:
[root@re ~]# cat /etc/init.d/tomcat-7001
1 #!/bin/bash 2 #chkconfig: 2 3 4 5 3 # Default-Stop: 0 1 6 4 # controe# the port 7001 to up and down 5 ###### 6 #kill process of port 7001 7 8 force_kill(){ 9 echo 'tomcat is stopping on the port 7001' 10 kill -9 `netstat -nutpl|egrep 7001|awk '{print $NF}'|cut -d"/" -f 1` 11 sleep 3 12 } 13 #start 14 start_tomcat(){ 15 echo 'tomcat is starting on the port 7001' 16 /wdjky/healthSH/tomcat/tomcat-7001/bin/startup.sh 17 } 18 19 useage(){ 20 echo "please enter as $(basename $0) start|stop " 21 22 } 23 case $1 in 24 start) 25 start_tomcat;; 26 stop) 27 force_kill;; 28 restart) 29 force_kill 30 start_tomcat 31 ;; 32 *) 33 useage;; 34 esac
自用优化脚本:
[root@kazihuo ~]# cat /scripts/tomcat
1 #!/bin/bash 2 #by kazihuo 2018/4/23 3 #description:start|stop|status the tomcat deamon 4 5 [ -f /etc/init.d/functions ] && . /etc/init.d/functions 6 7 PID=`ps -ef |grep tomcat|grep java|awk '{print $2}'` 8 9 Msg(){ 10 if [ $? -eq 0 ];then 11 action "Tomcat $1." /bin/true 12 else 13 action "Tmocat $1." /bin/false 14 fi 15 } 16 17 Start(){ 18 if [ -z $PID ];then 19 /usr/local/tomcat/bin/startup.sh &>/dev/null 20 Msg $1 21 else 22 echo -e "\033[32mTomcat is running.\033[0m" 23 fi 24 } 25 26 Stop(){ 27 if [[ -n $PID ]];then 28 ps -ef |grep tomcat|grep java|awk '{print $2}'|xargs kill -9 && sleep 3 29 Msg $1 30 else 31 echo -e "\033[32mTomcat is not running.\033[0m" 32 fi 33 } 34 35 Restart(){ 36 ps -ef |grep tomcat|grep java|awk '{print $2}'|xargs kill -9 && sleep 3 37 /usr/local/tomcat/bin/startup.sh &>/dev/null 38 Msg $1 39 } 40 41 Status(){ 42 if [[ -n $PID ]];then 43 echo "Tomcat is running." 44 else 45 echo "Tomcat is not running." 46 fi 47 } 48 49 Help(){ 50 echo -e "\033[32mUsage:\033[0m $0 start|stop|restart|status" 51 } 52 53 54 case $1 in 55 start) 56 Start 57 ;; 58 stop) 59 Stop 60 ;; 61 restart) 62 Restart 63 ;; 64 status) 65 Status 66 ;; 67 *) 68 Help 69 ;; 70 esac
========================================
作者:罗穆瑞
转载请保留此段声明,且在文章页面明显位置给出原文链接,谢谢!
==============================================================================
^_^ 如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,您的“推荐”将是我最大的写作动力 ^_^
==============================================================================
浙公网安备 33010602011771号