#!/bin/bash## chkconfig:- the the# Description:tomcat Start/stop/status script#location of Java_home (bin files) export Java_home=/usr/java/jdk1.7. 0_80#add Java binary files to pathexport PATH= $JAVA _home/bin: $PATH #catalina_home is the location of the the the configuration files of this instance of Tomcatcatalina_home=/usr/local/Tomcat#tomcat_user is the default USER of Tomcattomcat_user=www#tomcat_usage is the messageifThis script was called without any optionstomcat_usage="Usage: $ {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"#SHUTDOWN_WAIT iswait Time inchSeconds forJava proccess to stopshutdown_wait= -Tomcat_pid () {Echo`PS-ef |grep$CATALINA _home |grep-Vgrep|TR-S" "|Cut-D" "-F2 '}start () {PID=$ (tomcat_pid)if[-N"$pid"]; Then Echo-E"\e[00;31mtomcat is already running (PID: $pid) \e[00m" Else Echo-E"\e[00;32mstarting tomcat\e[00m" if[' user_exists $TOMCAT _user ' ="1"]; Then su$TOMCAT _user-c $CATALINA _home/bin/startup.SH Else$CATALINA _home/bin/startup.SH fiStatusfireturn0}status () {PID=$ (tomcat_pid)if[-N"$pid"]; Then Echo-E"\e[00;32mtomcat is running with PID: $pid \e[00m" Else Echo-E"\e[00;31mtomcat is not running\e[00m" fi}stop () {PID=$ (tomcat_pid)if[-N"$pid"]; Then Echo-E"\e[00;31mstoping tomcat\e[00m"$CATALINA _home/bin/shutdown.SHLet kwait=$SHUTDOWN _wait Count=0; until[ `PS-P $pid |grep-C $pid ' ='0'] || [$count-GT $kwait] Do Echo-n-e"\e[00;31mwaiting for processes to exit\e[00m\n"; Sleep 1Let count= $count +1; Done if[$count-gt $kwait]; Then Echo-n-e"\n\e[00;31mkilling processes which didn ' t stop after $SHUTDOWN _wait seconds\e[00m" Kill-9$pidfi Else Echo-E"\e[00;31mtomcat is not running\e[00m" fireturn0}user_exists () {if ID-U $1>/dev/NULL 2>&1; Then Echo "1" Else Echo "0" fi} Case$1 inchstart) Start; stop) stop;; restart) stop start;; status) status; *) Echo-e $TOMCAT _usage;;EsacExit0
Tomcat shell script (Start | off | restart | state)