RHEL 5.4 Tomcat 6 Startup Script (开机启动)
[edgen@rhel54 ~]$ su - root
口令:
[root@rhel54 rc3.d]# cd /etc/rc.d/init.d/
[root@rhel54 init.d]# vi tomcat
[root@rhel54 init.d]# cat tomcat
#!/bin/bash
# chkconfig: 345 90 10
# description: Tomcat 6 Startup Script
# /etc/rc.d/init.d/tomcat
?
TOMCAT_HOME=/usr/apache-tomcat-6.0.29
TOMCAT_START=$TOMCAT_HOME/bin/startup.sh
TOMCAT_STOP=$TOMCAT_HOME/bin/shutdown.sh
?
CATALINA_HOME=$TOMCAT_HOME
export JAVA_HOME=/usr/java/jdk1.6.0_23
?
. /etc/rc.d/init.d/functions
?
#. /etc/sysconfig/network
?
#[ "${NETWORKING}" = "no" ] && exit 0
?
if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]
then
?echo "Tomcat not valiable..."
?exit 1
fi
?
start(){
?echo -n "Starting Tomcat: "
?daemon $TOMCAT_START
?touch /var/lock/subsys/tomcat
?echo "OK"
}
?
stop(){
?echo -n "Shutting down Tomcat: "
?daemon $TOMCAT_STOP
?rm -f /var/lock/subsys/tomcat
?echo "OK"
}
?
restart(){
?stop
?sleep 3
?start
}
?
status(){
?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
??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
}
?
case "$1" in
?start)
??start
?;;
?stop)
??stop
?;;
?reload|restart)
??restart
?;;
?status)
??status
?;;
?*)
??echo "Usage: tomcat {start|stop|reload|restart|status}"
??exit 1
esac
?
exit 0
?
[root@rhel54 init.d]# chmod 755 tomcat
[root@rhel54 init.d]# ll | grep tomcat
-rwxr-xr-x 1 root?? root????? 1340 01-13 17:15 tomcat
?
[root@rhel54 init.d]# chkconfig --add tomcat
[root@rhel54 init.d]# chkconfig --list | grep tomcat
tomcat???????? ?0:关闭?1:关闭?2:关闭?3:启用?4:启用?5:启用?6:关闭
?
[root@rhel54 init.d]# service tomcat status
tomcat( pid 24843 24949 ) is running...
?
[root@rhel54 init.d]# ln -s /etc/rc.d/init.d/tomcat /etc/rc3.d/K10tomcat
[root@rhel54 init.d]# ln -s /etc/rc.d/init.d/tomcat /etc/rc4.d/K10tomcat
[root@rhel54 init.d]# ln -s /etc/rc.d/init.d/tomcat /etc/rc5.d/K10tomcat
?
[root@rhel54 init.d]# service tomcat stop
[root@rhel54 init.d]# service tomcat start