tomcat的初始化脚本(启动、退出、查看状态)
#!/bin/bash
#
# Startup script for the tomcat
#
# chkconfig: 345 80 15
# description: Tomcat is a Servlet+JSP Engine.
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
checkjava(){
if [ -z "$JAVA_HOME" ]; then
export JAVA_HOME=/usr/java/jdk1.5.0_15
fi
}
start(){
checkjava
checkrun
if [ $RETVAL -eq 0 ]; then
echo "Starting tomcat"
/usr/tomcat/bin/startup.sh
touch /var/lock/subsys/tomcat
else
echo "tomcat allready running"
fi
}
stop(){
checkjava
checkrun
if [ $RETVAL -eq 1 ]; then
echo "Shutting down tomcat"
/usr/tomcat/bin/shutdown.sh
#while [ $RETVAL -eq 1 ]; do
sleep 5
#checkrun
#done
rm -f /var/lock/subsys/tomcat
else
echo "tomcat not running"
fi
}
checkrun(){
ps ax --width=1000 | grep
"[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' |
wc | awk '{print $2}' >/tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
RETVAL=1
return $RETVAL
else
RETVAL=0
return $RETVAL
fi
}
status(){
checkrun
if [ $RETVAL -eq 1 ]; then
echo -n "Tomcat ( pid "
ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
echo -n ") is running..."
echo
else
echo "Tomcat is stopped"
fi
echo "---------------------------------------------"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
/usr/tomcat/bin/catalina.sh version
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
exit 0