我们一般在linux 上的生产环境管理tomcat 是使用tomcat 目录下面的几个sh 文件来控制的,有时候tomcat 进程会没有完全结束,然后我们再次启动很容易咋成启动二个tomcat 这里集成一个shell 命令来管理。
# description: Auto-starts tomcat
Dir="/tomcat/"
echo $Dir
RETVAL="0"
# See how we were called.
function start() {
echo -n "Starting Tomcat: "
cd $Dir
./bin/startup.sh
echo
}
function stop2() {
stop
echo >$Dir/logs/catalina.out
}
function stop() {
pid=$(ps -ef | grep -v 'grep' | egrep $Dir"bin/bootstrap.jar"| awk '{printf $2 " "}')
if [ "$pid" != "" ]; then
echo -n "tomcat ( pid $pid) is running"
echo
echo -n $"Shutting down Tomcat: "
cd $Dir
./bin/shutdown.sh
pid=$(ps -ef | grep -v 'grep' | egrep $Dir"bin/bootstrap.jar"| awk '{printf $2 " "}')
if [ "$pid" != "" ]; then
echo "kill tomcat process"
kill -9 "$pid"
fi
else
echo "Tomcat is stopped"
fi
status
}
function status()
{
pid=$(ps -ef | grep -v 'grep' | egrep $Dir"bin/bootstrap.jar"| awk '{printf $2 " "}')
#echo "$pid"
if [ "$pid" != "" ]; then
echo "tomcat is running,pid is $pid"
else
echo "tomcat is stopped"
fi
}
function usage()
{
echo "Usage: $0 {start|stop|stop2(stop and clear catalina.out)|restart|restart2(clear catalina.out)|reload|status}"
RETVAL="2"
}
# See how we were called.
RETVAL="0"
case "$1" in
start)
start
;;
stop)
stop
;;
stop2)
stop2
;;
restart)
stop
start
;;
restart2)
stop2
start
;;
reload)
RETVAL="3"
;;
status)
status
;;
*)
usage
;;
esac
exit $RETVAL