Linux下Tomcat啓動/中止/重啓腳本 來替代Tomcat自身的啓動/中止java
- #!/bin/bash
- #This script for tomcat service start/stop/restart/status
- #author:leo Email:chanyipiaomiao@163.com date:2011/12/25
- TOM_HOME="/usr/local/tomcat6.0.33"
- TOM_PATH="${TOM_HOME}/bin"
- TOM_STATUS=$( ps -ef | grep -v 'grep' | egrep "java.*=${TOM_HOME}")
- function tomcatstart() {
- if [ "${TOM_STATUS}X" == "X" ];then
- ${TOM_PATH}/startup.sh
- START_STATUS=$( ps -ef | grep -v 'grep' | egrep "java.*=${TOM_HOME}")
- while [ "X" = "X" ]
- do
- if [ "${START_STATUS}" != "" ];then
- echo
- echo "Tomcat Service Start......................[OK]"
- echo
- break
- fi
- START_STATUS=$( ps -ef | grep -v 'grep' | egrep "java.*=${TOM_HOME}")
- done
- else
- echo
- echo "Tomcat Service is Running...."
- echo
- exit 1
- fi
- }
- function tomcatstop() {
- if [ "${TOM_STATUS}X" != "X" ];then
- ${TOM_PATH}/shutdown.sh
- STOP_STATUS=$(ps -ef | grep -v 'grep' | egrep "java.*=${TOM_HOME}")
- while [ "X" == "X" ]
- do
- if [ "${STOP_STATUS}" == "" ];then
- echo
- echo "Tomcat Service Stop......................[OK]"
- echo
- break
- fi
- STOP_STATUS=$(ps -ef | grep -v 'grep' | egrep "java.*=${TOM_HOME}")
- done
- else
- echo
- echo "Tomcat Service is not Running..."
- echo
- exit 1
- fi
- TOM_STATUS=""
- }
- function tomcatstatus() {
- if [ "${TOM_STATUS}X" == "X" ];then
- echo
- echo "Tomcat Service is not Running..."
- echo
- exit 1
- else
- echo
- echo "Tomcat Service is Running...."
- echo
- exit 1
- fi
- }
- function tomcatrestart() {
- if [ "${TOM_STATUS}X" == "X" ];then
- echo
- echo "Tomcat Service is not Running..."
- echo
- tomcatstart
- else
- tomcatstop
- tomcatstart
- fi
- }
- case $1 in
- "start")
- tomcatstart
- ;;
- "stop")
- tomcatstop
- ;;
- "status")
- tomcatstatus
- ;;
- "restart")
- tomcatrestart
- ;;
- *)
- echo
- echo "Usage: $0 start|stop|restart|status"
- echo
- esac