Tomcat shell script (Start | off | restart | state)

Source: Internet
Author: User

#!/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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.