Tomcat Maintenance Scripts

Source: Internet
Author: User

Tag: Tomcat start stop restart

#!/bin/bash## chkconfig: - 99 28# description: starts/stops/restart tomcat#    #Location  of JAVA_HOME  (bin files) export java_home=/usr/local/java # Add java binary files to pathexport path= $JAVA _home/bin: $PATH   #CATALINA_ Home is the location of the bin files of tomcat  export  CATALINA_HOME=/root/tomcat-test01  #CATALINA_BASE  is the location of the  configuration files of this instance of tomcatexport catalina_base=/ root/tomcat-test01  #TOMCAT_USER  is the default user of tomcatexport  tomcat_user=root  #TOMCAT_USAGE  is the message if this script is  Called without any optionstomcat_usage= "Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop \e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m} "  #SHUTDOWN_WAIT  is wait time in seconds  For java proccess to stopshutdown_wait=20 tomcat_pid ()  {#   echo   ' ps -fe | grep  $CATALINA _base | grep -v grep | tr  -s  " " |cut -d   " -f2 '     echo  ' ps -fe |  grep  $CATALINA _base | grep  $JAVA _home | grep -v grep |  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     # Start tomcat    echo -e  "\e[00;32mstarting tomcat\e[00m"      #ulimit -n 100000     #umask  007    #/bin/su -p -s  /bin/sh tomcat        if [  ' user_exists $ Tomcat_user '  =  "1"  ]        then                 su  $TOMCAT _user -c   $CATALINA _home/bin/startup.sh        else                 sh  $CATALINA _home/bin/ startup.sh        fi         Status  fi  return 0} 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"     #/bin/su -p -s /bin/ sh tomcat        sh  $CATALINA _home/bin/shutdown.sh      let kwait= $SHUTDOWN _wait    count=0;     until [  ' ps -p  $pid  | grep -c  $pid '  =  ' 0 '  ] | |  [  $count  -gt  $kwait  ]    do       echo -n -e  "\n\e[00;31mwaiting for processes to exit\e[00m ";       sleep  1      let 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  $pid      fi  else    echo -e  "\e[00;31mtomcat is not  running\e[00m "  fi   return 0} user_exists () {         if id -u $1 >/dev/null 2>&1; then         echo  "1"         else                 echo  "0"          fi} case $1 in         start)           start         ;;                stop)              stop         ;;                restart)            stop           start        ;;                status)                  status                        ;;                *)                  echo -e  $TOMCAT _usage         ;; Esac    exit 0

This article is from the "Cold Tea" blog, please be sure to keep this source http://miaocbin.blog.51cto.com/689091/1812544

Tomcat Maintenance Scripts

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.