#!/bin/bash
source /usr/local/application/tomcat/.bash_profile
TOMCAT_NAME=tomcat7
TOMCAT_HOME=/usr/local/application/tomcat/tomcat7
TOMCAT_PID=`ps -ef | grep ${TOMCAT_NAME} | grep -v "grep" | awk '{print $2}'`
usage(){
echo -e "\e[1;32m Usage: $0 [ start | stop | status ] \e[0m"
}
TOMCAT_START(){
if [ "${TOMCAT_PID}" = "" ]
then
echo -e "\e[1;32m ${TOMCAT_NAME} is not running; start-up ${TOMCAT_NAME} \e[0m"
${TOMCAT_HOME}/bin/startup.sh
else
echo -e "\e[1;32m ${TOMCAT_NAME} is running,PID: ${TOMCAT_PID} \e[0m"
${TOMCAT_HOME}/bin/shutdown.sh
echo -e "\e[1;32m ${TOMCAT_PID} killed \e[0m"
kill -9 ${TOMCAT_PID}
${TOMCAT_HOME}/bin/startup.sh
fi
}
TOMCAT_STOP(){
if [ "${TOMCAT_PID}" = "" ]
then
echo -e "\e[1;32m ${TOMCAT_NAME} is not running. \e[0m"
else
${TOMCAT_HOME}/bin/shutdown.sh
fi
}
TOMCAT_STATUS(){
if [ "${TOMCAT_PID}" = "" ]
then
echo -e "\e[1;32m ${TOMCAT_NAME} is not running. \e[0m"
else
echo -e "\e[1;32m ${TOMCAT_NAME} is running. \e[0m"
fi
}
main(){
case $1 in
start)
TOMCAT_START
;;
stop)
TOMCAT_STOP
;;
status)
TOMCAT_STATUS
;;
*)
usage;
esac
}
main $1;
原文地址:http://blog.51cto.com/visitor/2055488