Put it in the tomcat installation path, you can implement the tomcat command function
Go directly to the code: save the paste in the horizontal line as tomcat.sh
---------------------------------------------------
#!/bin/sh
# chkconfig: 345 08 92
# description: Tomcat daemon start/stop scripts
################################################################################
# #
# Tomcat Scripts 1.0.0 #
# #
# used:tomcat.sh start #
# tomcat.sh stop #
# tomcat.sh restart #
# tomcat.sh status #
# tomcat.sh islive#
################################################################################
#how cut and delete log
#crontab -e
#1 0 * * * /opt/tomcat-6.0.37/tomcat.sh flush > /dev/null 2>&1
PRG=$0
PRGDIR=`dirname "$PRG"`
#These two lines mean to get the current directory
TOMCAT_HOME=`cd "$PRGDIR" ; pwd`
#Get the tomcat path
TOMCAT_LOGS=$TOMCAT_HOME/logs
TOMCAT_WORK=$TOMCAT_HOME/work
TOMCAT_TEMP=$TOMCAT_HOME/temp
# . /etc/rc.d/init.d/functions
start() {
is live
RETVAL=$?
if [ "$RETVAL" = "1" ]
then
cd $TOMCAT_HOME
if [ -d $TOMCAT_WORK ]
then
rm -rf $TOMCAT_WORK/*
be
if [ -d $TOMCAT_TEMP ]
then
rm -rf $TOMCAT_TEMP/*
be
bin/startup.sh
else
echo Tomcat[$pids] is running!
be
}
stop() {
is live
RETVAL=$?
if [ "$RETVAL" = "0" ]
then
cd $TOMCAT_HOME
# bin/shutdown.sh
# sleep 5
echo Tomcat[$pids] is killed!
kill -9 $pids
else
echo Tomcat is not running!
be
}
status() {
is live
RETVAL=$?
if [ "$RETVAL" = "0" ]
then
echo Tomcat[$pids] is running!
RETVAL=0
else
echo "Tomcat is stoped"
RETVAL=1
be
return $RETVAL
}
flush() {
cd $TOMCAT_LOGS
cat catalina.out >> catalina.$(date -d "yesterday" +"%Y-%m-%d").out
echo "" > catalina.out
find . -type f -mtime +7 -delete
find . -type d -mtime +7 -delete
}
restart() {
stop
sleep 3
start
}
islive() {
pids=`ps -ef|grep "$TOMCAT_HOME/bin/bootstrap.jar" | grep -v "grep"|awk '{print $2}'`
if [ "$pids" = "" ]
then
RETVAL=1
else
RETVAL=0
be
return $RETVAL
}
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart)
restart
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
flush)
flush
;;
*)
echo $"Usage: $0 {start|stop|restart|status|flush}"
exit 1
;;
esac
exit $RETVAL
----------------------------------------------------------