#!/bin/bash
usage() {
echo "Usage: $0 [start|stop|restart|status]"
}
start_tomcat(){
/usr/local/tomcat/bin/startup.sh
}
status_tomcat(){
ps -ef|grep java|grep tomcat|grep -v grep
}
stop_tomcat(){
TPID=$(ps -ef|grep java|grep tomcat|grep -v grep|awk '{print $2}')
kill -9 $TPID
sleep 3
STAT=$(ps -ef|grep java|grep tomcat|grep -v grep|awk '{print $2}')
if [ -z $STAT ];then
echo 'tomcat stoped...'
else
kill -9 $STAT
fi
}
restart_tomcat(){
stop_tomcat
start_tomcat
}
main(){
case $1 in
start)
start_tomcat;;
stop)
stop_tomcat;;
restart)
restart_tomcat;;
status)
status_tomcat;;
*)
usage;
esac
}
main $1