[root@Tomcat conf]# cd /opt/
[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


点击(此处)折叠或打开

  1. [root@Tomcat bin]# more /etc/init.d/TomcatA
  2. #!/bin/bash
  3. #chkconfig: 2345 10 90
  4. #description:TomcatA service
  5. JAVA_HOME=/opt/jdk1.7.0_21
  6. CATALINA_HOME=/opt/TomcatA
  7. TOMCAT_START=$CATALINA_HOME/bin/startup.sh
  8. TOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh

  9. # source function library.
  10. . /etc/rc.d/init.d/functions
  11. # check that networking is up.
  12. [ "${NETWORKING}" = "no" ] && exit 0
  13. # check for tomcat script
  14. if [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then
  15.          echo "TomcatA not valilable..."
  16.         exit
  17. fi
  18. start(){
  19.         echo -n "Starting TomcatA: "
  20.         daemon $TOMCAT_START
  21.         echo
  22.         touch /var/lock/subsys/tomcat
  23. }
  24. stop(){
  25.                 ps ax --width=1000 | grep "/opt/TomcatA/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  26.  | wc | awk '{print $2}' > /tmp/tomcatA_process_count.txt
  27.         read line < /tmp/tomcatA_process_count.txt
  28.         if [ $line -gt 0 ]; then
  29.                 echo -n "TomcatA ( pid "
  30.                 ps ax --width=1000 | grep "/opt/TomcatA/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  31.                 echo -n ") is running..."
  32.                                 echo

  33.                                 echo -n $"Shutting down TomcatA: "
  34.                                 daemon $TOMCAT_STOP
  35.                                 rm -f /var/lock/subsys/tomcat.pid echo
  36.         else
  37.                 echo "TomcatA is stopped"
  38.         fi
  39. }
  40. restart(){
  41.         stop
  42.         start
  43. }
  44. status(){
  45.         ps ax --width=1000 | grep "/opt/TomcatA/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  46.  | wc | awk '{print $2}' > /tmp/tomcatA_process_count.txt
  47.         read line < /tmp/tomcatA_process_count.txt
  48.         if [ $line -gt 0 ]; then
  49.                 echo -n "TomcatA ( pid "
  50.                 ps ax --width=1000 | grep "/opt/TomcatA/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  51.                 echo -n ") is running..."
  52.                 echo
  53.         else
  54.                 echo "TomcatA is stopped"
  55.         fi
  56. }
  57. case "$1" in
  58.         start)
  59.                 start ;;
  60.         stop)
  61.                 stop ;;
  62.         restart)
  63.                 stop
  64.                 sleep 3
  65.                 start ;;
  66.         status)
  67.                 status ;;
  68.         *)
  69.                 echo "Usage: TomcatA {start|stop|restart|status}"
  70.                 exit 1
  71. esac
  72. exit 0

  73. [root@Tomcat bin]#

点击(此处)折叠或打开

  1. [root@Tomcat bin]# more /etc/init.d/TomcatB
  2. #!/bin/bash
  3. #chkconfig: 2345 10 90
  4. #description:TomcatB service
  5. JAVA_HOME=/opt/jdk1.7.0_21
  6. CATALINA_HOME=/opt/TomcatB
  7. TOMCAT_START=$CATALINA_HOME/bin/startup.sh
  8. TOMCAT_STOP=$CATALINA_HOME/bin/shutdown.sh

  9. # source function library.
  10. . /etc/rc.d/init.d/functions
  11. # check that networking is up.
  12. [ "${NETWORKING}" = "no" ] && exit 0
  13. # check for tomcat script
  14. if [ ! -f $CATALINA_HOME/bin/catalina.sh ]; then
  15.          echo "TomcatB not valilable..."
  16.         exit
  17. fi
  18. start(){
  19.         echo -n "Starting TomcatB: "
  20.         daemon $TOMCAT_START
  21.         echo
  22.         touch /var/lock/subsys/tomcat
  23. }
  24. stop(){
  25.                 ps ax --width=1000 | grep "/opt/TomcatB/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  26.  | wc | awk '{print $2}' > /tmp/tomcatB_process_count.txt
  27.         read line < /tmp/tomcatB_process_count.txt
  28.         if [ $line -gt 0 ]; then
  29.                 echo -n "TomcatB ( pid "
  30.                 ps ax --width=1000 | grep "/opt/TomcatB/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  31.                 echo -n ") is running..."
  32.                                 echo

  33.                                 echo -n $"Shutting down Tomcat: "
  34.                                 daemon $TOMCAT_STOP
  35.                                 rm -f /var/lock/subsys/tomcat.pid echo
  36.         else
  37.                 echo "TomcatB is stopped"
  38.         fi
  39. }
  40. restart(){
  41.         stop
  42.         start
  43. }
  44. status(){
  45.         ps ax --width=1000 | grep "/opt/TomcatB/temp [o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  46.  | wc | awk '{print $2}' > /tmp/tomcatB_process_count.txt
  47.         read line < /tmp/tomcatB_process_count.txt
  48.         if [ $line -gt 0 ]; then
  49.                 echo -n "TomcatB ( pid "
  50.                 ps ax --width=1000 | grep "/opt/TomcatB/temp org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
  51.                 echo -n ") is running..."
  52.                 echo
  53.         else
  54.                 echo "TomcatB is stopped"
  55.         fi
  56. }
  57. case "$1" in
  58.         start)
  59.                 start ;;
  60.         stop)
  61.                 stop ;;
  62.         restart)
  63.                 stop
  64.                 sleep 3
  65.                 start ;;
  66.         status)
  67.                 status ;;
  68.         *)
  69.                 echo "Usage: TomcatB {start|stop|restart|status}"
  70.                 exit 1
  71. esac
  72. exit 0

  73. [root@Tomcat bin]
在2个tomcat的bin目录下修改setclasspath.sh,添加JAVA_HOME环境变量

点击(此处)折叠或打开

  1. [root@Tomcat bin]# more /opt/TomcatA/bin/setclasspath.sh
  2. #!/bin/sh

  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.

  17. # -----------------------------------------------------------------------------
  18. # Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings
  19. # are valid and consistent with the selected start-up options and set up the
  20. # endorsed directory.
  21. #
  22. # $Id: setclasspath.sh 1430568 2013-01-08 22:08:57Z schultz $
  23. # -----------------------------------------------------------------------------
  24. export JAVA_HOME=/opt/jdk1.7.0_21

  25. # Make sure prerequisite environment variables are set
  26. if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
  27.   if $darwin; then
  28.     # Bugzilla 54390
  29.     if [ -x '/usr/libexec/java_home' ] ; then
  30.       export JAVA_HOME=`/usr/libexec/java_home`
  31.     # Bugzilla 37284 (reviewed).
  32.     elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
  33.       export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
  34.     fi
  35.   else
  36.     JAVA_PATH=`which java 2>/dev/null`
  37.     if [ "x$JAVA_PATH" != "x" ]; then
  38.       JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
  39.       JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
  40.     fi
  41.     if [ "x$JRE_HOME" = "x" ]; then
  42.       # XXX: Should we try other locations?
  43.       if [ -x /usr/bin/java ]; then
  44.         JRE_HOME=/usr
  45.       fi
  46.     fi
  47.   fi
  48.   if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
  49.     echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
  50.     echo "At least one of these environment variable is needed to run this program"
  51.     exit 1
  52.   fi
  53. fi
  54. if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then
  55.   echo "JAVA_HOME should point to a JDK in order to run in debug mode."
  56.   exit 1
  57. fi
  58. if [ -z "$JRE_HOME" ]; then
  59.   JRE_HOME="$JAVA_HOME"
  60. fi

  61. # If we're running under jdb, we need a full jdk.
  62. if [ "$1" = "debug" ] ; then
  63.   if [ "$os400" = "true" ]; then
  64.     if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then
  65.       echo "The JAVA_HOME environment variable is not defined correctly"
  66.       echo "This environment variable is needed to run this program"
  67.       echo "NB: JAVA_HOME should point to a JDK not a JRE"
  68.       exit 1
  69.     fi
  70.   else
  71.     if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then
  72.       echo "The JAVA_HOME environment variable is not defined correctly"
  73.       echo "This environment variable is needed to run this program"
  74.       echo "NB: JAVA_HOME should point to a JDK not a JRE"
  75.       exit 1
  76.     fi
  77.   fi
  78. fi

  79. # Don't override the endorsed dir if the user has set it previously
  80. if [ -z "$JAVA_ENDORSED_DIRS" ]; then
  81.   # Set the default -Djava.endorsed.dirs argument
  82.   JAVA_ENDORSED_DIRS="$CATALINA_HOME"/endorsed
  83. fi

  84. # Set standard commands for invoking Java.
  85. _RUNJAVA="$JRE_HOME"/bin/java
  86. if [ "$os400" != "true" ]; then
  87.   _RUNJDB="$JAVA_HOME"/bin/jdb
  88. fi
  89. [root@Tomcat bin]

 

01-16 04:14