[root@Tomcat opt]# ll
total 16
drwxr-xr-x. 8 500 500 4096 Apr 4 19:52 jdk1.7.0_21
drwxr-xr-x. 2 root root 4096 May 10 2012 rh
drwxr-xr-x. 9 root root 4096 May 31 00:23 TomcatA
drwxr-xr-x. 9 root root 4096 May 31 00:26 TomcatB
[root@Tomcat opt]# ls /etc/init.d/Tomcat*
/etc/init.d/TomcatA /etc/init.d/TomcatB
[root@Tomcat opt]# ls /tmp/
hsperfdata_root tomcatA_process_count.txt tomcatB_process_count.txt yum.log
[root@Tomcat opt]# chkconfig --add TomcatA
[root@Tomcat opt]# chkconfig --add TomcatB
[root@Tomcat opt]# chkconfig --list|grep Tomcat
TomcatA 0:off 1:off 2:on 3:on 4:on 5:on 6:off
TomcatB 0:off 1:off 2:on 3:on 4:on 5:on 6:off
点击(此处)折叠或打开
- [root@Tomcat bin]# more /etc/init.d/TomcatA
- #!/bin/bash
- #chkconfig: 2345 10 90
- #description:TomcatA service
- JAVA_HOME=/opt/jdk1.7.0_21
- CATALINA_HOME=/opt/TomcatA
- TOMCAT_START=$CATALINA_HOME/bin/startup.sh
- TOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh
- # source function library.
- . /etc/rc.d/init.d/functions
- # check that networking is up.
- [ "${NETWORKING}" = "no" ] && exit 0
- # check for tomcat script
- if [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then
- echo "TomcatA not valilable..."
- exit
- fi
- start(){
- echo -n "Starting TomcatA: "
- daemon $TOMCAT_START
- echo
- touch /var/lock/subsys/tomcat
- }
- stop(){
- ps ax --width=1000 | grep "/opt/TomcatA/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
- | wc | awk '{print $2}' > /tmp/tomcatA_process_count.txt
- read line < /tmp/tomcatA_process_count.txt
- if [ $line -gt 0 ]; then
- echo -n "TomcatA ( pid "
- ps ax --width=1000 | grep "/opt/TomcatA/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
- echo -n ") is running..."
- echo
- echo -n $"Shutting down TomcatA: "
- daemon $TOMCAT_STOP
- rm -f /var/lock/subsys/tomcat.pid echo
- else
- echo "TomcatA is stopped"
- fi
- }
- restart(){
- stop
- start
- }
- status(){
- ps ax --width=1000 | grep "/opt/TomcatA/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
- | wc | awk '{print $2}' > /tmp/tomcatA_process_count.txt
- read line < /tmp/tomcatA_process_count.txt
- if [ $line -gt 0 ]; then
- echo -n "TomcatA ( pid "
- ps ax --width=1000 | grep "/opt/TomcatA/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
- echo -n ") is running..."
- echo
- else
- echo "TomcatA is stopped"
- fi
- }
- case "$1" in
- start)
- start ;;
- stop)
- stop ;;
- restart)
- stop
- sleep 3
- start ;;
- status)
- status ;;
- *)
- echo "Usage: TomcatA {start|stop|restart|status}"
- exit 1
- esac
- exit 0
- [root@Tomcat bin]#
点击(此处)折叠或打开
- [root@Tomcat bin]# more /etc/init.d/TomcatB
- #!/bin/bash
- #chkconfig: 2345 10 90
- #description:TomcatB service
- JAVA_HOME=/opt/jdk1.7.0_21
- CATALINA_HOME=/opt/TomcatB
- TOMCAT_START=$CATALINA_HOME/bin/startup.sh
- TOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh
- # source function library.
- . /etc/rc.d/init.d/functions
- # check that networking is up.
- [ "${NETWORKING}" = "no" ] && exit 0
- # check for tomcat script
- if [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then
- echo "TomcatB not valilable..."
- exit
- fi
- start(){
- echo -n "Starting TomcatB: "
- daemon $TOMCAT_START
- echo
- touch /var/lock/subsys/tomcat
- }
- stop(){
- ps ax --width=1000 | grep "/opt/TomcatB/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
- | wc | awk '{print $2}' > /tmp/tomcatB_process_count.txt
- read line < /tmp/tomcatB_process_count.txt
- if [ $line -gt 0 ]; then
- echo -n "TomcatB ( pid "
- ps ax --width=1000 | grep "/opt/TomcatB/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
- echo -n ") is running..."
- echo
- echo -n $"Shutting down Tomcat: "
- daemon $TOMCAT_STOP
- rm -f /var/lock/subsys/tomcat.pid echo
- else
- echo "TomcatB is stopped"
- fi
- }
- restart(){
- stop
- start
- }
- status(){
- ps ax --width=1000 | grep "/opt/TomcatB/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
- | wc | awk '{print $2}' > /tmp/tomcatB_process_count.txt
- read line < /tmp/tomcatB_process_count.txt
- if [ $line -gt 0 ]; then
- echo -n "TomcatB ( pid "
- ps ax --width=1000 | grep "/opt/TomcatB/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
- echo -n ") is running..."
- echo
- else
- echo "TomcatB is stopped"
- fi
- }
- case "$1" in
- start)
- start ;;
- stop)
- stop ;;
- restart)
- stop
- sleep 3
- start ;;
- status)
- status ;;
- *)
- echo "Usage: TomcatB {start|stop|restart|status}"
- exit 1
- esac
- exit 0
- [root@Tomcat bin]
点击(此处)折叠或打开
- [root@Tomcat bin]# more /opt/TomcatA/bin/setclasspath.sh
- #!/bin/sh
- # Licensed to the Apache Software Foundation (ASF) under one or more
- # contributor license agreements. See the NOTICE file distributed with
- # this work for additional information regarding copyright ownership.
- # The ASF licenses this file to You under the Apache License, Version 2.0
- # (the "License"); you may not use this file except in compliance with
- # the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- # -----------------------------------------------------------------------------
- # Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings
- # are valid and consistent with the selected start-up options and set up the
- # endorsed directory.
- #
- # $Id: setclasspath.sh 1430568 2013-01-08 22:08:57Z schultz $
- # -----------------------------------------------------------------------------
- export JAVA_HOME=/opt/jdk1.7.0_21
- # Make sure prerequisite environment variables are set
- if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
- if $darwin; then
- # Bugzilla 54390
- if [ -x '/usr/libexec/java_home' ] ; then
- export JAVA_HOME=`/usr/libexec/java_home`
- # Bugzilla 37284 (reviewed).
- elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
- export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
- fi
- else
- JAVA_PATH=`which java 2>/dev/null`
- if [ "x$JAVA_PATH" != "x" ]; then
- JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
- JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
- fi
- if [ "x$JRE_HOME" = "x" ]; then
- # XXX: Should we try other locations?
- if [ -x /usr/bin/java ]; then
- JRE_HOME=/usr
- fi
- fi
- fi
- if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
- echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
- echo "At least one of these environment variable is needed to run this program"
- exit 1
- fi
- fi
- if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then
- echo "JAVA_HOME should point to a JDK in order to run in debug mode."
- exit 1
- fi
- if [ -z "$JRE_HOME" ]; then
- JRE_HOME="$JAVA_HOME"
- fi
- # If we're running under jdb, we need a full jdk.
- if [ "$1" = "debug" ] ; then
- if [ "$os400" = "true" ]; then
- if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then
- echo "The JAVA_HOME environment variable is not defined correctly"
- echo "This environment variable is needed to run this program"
- echo "NB: JAVA_HOME should point to a JDK not a JRE"
- exit 1
- fi
- else
- if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then
- echo "The JAVA_HOME environment variable is not defined correctly"
- echo "This environment variable is needed to run this program"
- echo "NB: JAVA_HOME should point to a JDK not a JRE"
- exit 1
- fi
- fi
- fi
- # Don't override the endorsed dir if the user has set it previously
- if [ -z "$JAVA_ENDORSED_DIRS" ]; then
- # Set the default -Djava.endorsed.dirs argument
- JAVA_ENDORSED_DIRS="$CATALINA_HOME"/endorsed
- fi
- # Set standard commands for invoking Java.
- _RUNJAVA="$JRE_HOME"/bin/java
- if [ "$os400" != "true" ]; then
- _RUNJDB="$JAVA_HOME"/bin/jdb
- fi
- [root@Tomcat bin]