#!/bin/bash
# description: Tomcat is a Java Servlet Container
. /etc/profile
TOMCAT_HOME=/usr/local/abcdocker-test
start () {
TOMCAT_PID=`ps -ef |grep "$TOMCAT_HOME" |grep -v "grep" |awk '{print $2}'`
if [ -z $TOMCAT_PID ];then
    /bin/bash $TOMCAT_HOME/bin/startup.sh
else
    echo "$0 is  running"
fi
}
stop () {
TOMCAT_PID=`ps -ef |grep "$TOMCAT_HOME" |grep -v "grep" |awk '{print $2}'`
if [ -z $TOMCAT_PID ];then
        echo "$0 is not running"
else
        echo "shutting down $0"
        kill -9 "$TOMCAT_PID" && echo "PID $TOMCAT_PID killed."
fi
}
status () {
TOMCAT_PID=`ps -ef |grep "$TOMCAT_HOME" |grep -v "grep" |awk '{print $2}'`
if [ -z $TOMCAT_PID ];then
        echo "$0 is not running"
else
        echo "$0 is running PID is $TOMCAT_PID"
fi
}
case $1 in
start)
start
#tail -f $TOMCAT_HOME/logs/catalina.out
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
#tail -f $TOMCAT_HOME/logs/catalina.out
;;
*)
echo "Usage:$0  {start|stop|status|restart}."
;;
esac
