tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup Catalina.java
Date Sun, 13 Feb 2000 07:09:31 GMT
craigmcc    00/02/12 23:09:31

  Modified:    proposals/catalina build.xml
               proposals/catalina/src/share/org/apache/tomcat/core
                        ContainerBase.java
  Added:       proposals/catalina/src/bin catalina.sh
               proposals/catalina/src/share/org/apache/tomcat/startup
                        Catalina.java
  Log:
  Add the beginnings of a startup/shutdown shell for Catalina, modelled
  after the current one used by Tomcat (and using the cool XML parsing and
  introspection code that Costin built).
  
  Modify ContainerBase so that when
  set{Loader/Logger/Manager/Realm/Resources} gets called, the container
  calls the setContainer() method of the corresponding object.  This ensures
  that the two-way linkage is established from a single set method.
  
  Revision  Changes    Path
  1.3       +2 -0      jakarta-tomcat/proposals/catalina/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/build.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build.xml	2000/02/13 03:01:00	1.2
  +++ build.xml	2000/02/13 07:09:30	1.3
  @@ -9,6 +9,7 @@
     <!-- Create directories and copy static files -->
     <target name="prepare">
       <mkdir dir="${catalina.build}"/>
  +    <mkdir dir="${catalina.build}/bin"/>
       <mkdir dir="${catalina.build}/classes"/>
       <mkdir dir="${catalina.build}/conf"/>
       <mkdir dir="${catalina.build}/etc"/>
  @@ -16,6 +17,7 @@
       <mkdir dir="${catalina.build}/lib"/>
       <copyfile src="${jakarta.tools}/projectx-tr2.jar"
                dest="${catalina.build}/lib/xml.jar"/>
  +    <copydir src="src/bin"  dest="${catalina.build}/bin"/>
       <copydir src="src/conf" dest="${catalina.build}/conf"/>
     </target>
   
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/bin/catalina.sh
  
  Index: catalina.sh
  ===================================================================
  #!/bin/sh
  #
  # $Id: catalina.sh,v 1.1 2000/02/13 07:09:30 craigmcc Exp $
  
  # Shell script to start and stop the server
  
  # There are other, simpler commands to startup the runner. The two
  # commented commands good replacements. The first works well with
  # Java Platform 1.1 based runtimes. The second works well with
  # Java2 Platform based runtimes.
  
  #jre -cp runner.jar:servlet.jar:classes org.apache.tomcat.shell.Startup $*
  #java -cp runner.jar:servlet.jar:classes org.apache.tomcat.shell.Startup $*
  
  if [ -f $HOME/.catalinarc ] ; then 
    . $HOME/.catalinarc
  fi
  
  if [ "$CATALINA_HOME" = "" ] ; then
    # try to find catalina
    if [ -d ${HOME}/opt/catalina/conf ] ; then 
      CATALINA_HOME=${HOME}/opt/catalina
    fi
  
    if [ -d /opt/catalina/conf ] ; then 
      CATALINA_HOME=/opt/catalina
    fi
  
    ## resolve links - $0 may be a link to ant's home
    PRG=$0
    progname=`basename $0`
    
    while [ -h "$PRG" ] ; do
      ls=`ls -ld "$PRG"`
      link=`expr "$ls" : '.*-> \(.*\)$'`
      if expr "$link" : '.*/.*' > /dev/null; then
  	PRG="$link"
      else
  	PRG="`dirname $PRG`/$link"
      fi
    done
    
    CATALINA_HOME=`dirname "$PRG"`/..
    echo CATALINA_HOME is $CATALINA_HOME
  
  fi
  
  if [ -z "$JAVA_HOME" ] ;  then
    JAVACMD=`which java`
    if [ -z "$JAVACMD" ] ; then
      echo "Cannot find JAVA. Please set your PATH."
      exit 1
    fi
    JAVA_BINDIR=`dirname $JAVACMD`
    JAVA_HOME=$JAVA_BINDIR/..
  fi
  
  if [ "$JAVACMD" = "" ] ; then 
     # it may be defined in env - including flags!!
     JAVACMD=$JAVA_HOME/bin/java
  fi
  
  
  oldCP=$CLASSPATH
   
  CLASSPATH=.
  for i in ${CATALINA_HOME}/lib/* ; do
    CLASSPATH=${CLASSPATH}:$i
  done
  
  CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar
  echo XXX $CLASSPATH
  
  
  # Backdoor classpath setting for development purposes when all classes
  # are compiled into a /classes dir and are not yet jarred.
  if [ -d ${CATALINA_HOME}/classes ]; then
      CLASSPATH=${CATALINA_HOME}/classes:${CLASSPATH}
  fi
  
  if [ "$oldCP" != "" ]; then
      CLASSPATH=${CLASSPATH}:${oldCP}
  fi
  
  # Add Tomcat build classes
  CLASSPATH=${CLASSPATH}:../tomcat/classes
  
  export CLASSPATH
  
  if [ ! -f server.xml ] ; then 
     if [ "$2" = "" ] ; then
       # Probably we are in a wrong directory, use catalina_home
       # If arguments are passed besides start/stop, probably a -f was used,
       # or the user knows what he's doing
       echo cd ${CATALINA_HOME} 
       cd ${CATALINA_HOME}
     fi
  fi
  
  # We start the server up in the background for a couple of reasons:
  #   1) It frees up your command window
  #   2) You should use `stop` option instead of ^C to bring down the server
  if [ "$1" = "start" ] ; then 
    shift 
    echo Using classpath: ${CLASSPATH}
    $JAVACMD org.apache.tomcat.startup.Catalina "$@" &
  #   $JAVACMD org.apache.tomcat.shell.Startup "$@" &
  
  elif [ "$1" = "stop" ] ; then 
    shift 
    echo Using classpath: ${CLASSPATH}
    $JAVACMD org.apache.tomcat.startup.Catalina -stop "$@"
  #   $JAVACMD org.apache.tomcat.shell.Shutdown "$@"
  
  elif [ "$1" = "run" ] ; then 
    shift 
    echo Using classpath: ${CLASSPATH}
    $JAVACMD org.apache.tomcat.startup.Catalina "$@" 
  #  $JAVACMD org.apache.tomcat.shell.Startup "$@" 
    # no &
  
  ## Call it with source catalina.sh to set the env for catalina
  elif [ "$1" = "env" ] ; then 
    shift 
    echo Setting classpath to: ${CLASSPATH}
    oldCP=$CLASSPATH
  
  else
    echo "Usage:"
    echo "catalina (start|env|run|stop)"
    echo "        start - start catalina in the background"
    echo "        run   - start catalina in the foreground"
    echo "        stop  - stop catalina"
    echo "        env  -  set CLASSPATH and CATALINA_HOME env. variables"
  
    exit 0
  fi
  
  
  if [ "$oldCP" != "" ]; then
      CLASSPATH=${oldCP}
      export CLASSPATH
  else
      unset CLASSPATH
  fi
  
  
  
  1.7       +14 -4     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java
  
  Index: ContainerBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ContainerBase.java	2000/01/29 21:01:10	1.6
  +++ ContainerBase.java	2000/02/13 07:09:30	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v
1.6 2000/01/29 21:01:10 craigmcc Exp $
  - * $Revision: 1.6 $
  - * $Date: 2000/01/29 21:01:10 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v
1.7 2000/02/13 07:09:30 craigmcc Exp $
  + * $Revision: 1.7 $
  + * $Date: 2000/02/13 07:09:30 $
    *
    * ====================================================================
    *
  @@ -146,7 +146,7 @@
    * class comments of the implementation class.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.6 $ $Date: 2000/01/29 21:01:10 $
  + * @version $Revision: 1.7 $ $Date: 2000/02/13 07:09:30 $
    */
   
   public abstract class ContainerBase
  @@ -341,6 +341,8 @@
   
   	Loader oldLoader = this.loader;
   	this.loader = loader;
  +	if (this.loader != null)
  +	    this.loader.setContainer(this);
   	support.firePropertyChange("loader", oldLoader, this.loader);
   
       }
  @@ -371,6 +373,8 @@
   
   	Logger oldLogger = this.logger;
   	this.logger = logger;
  +	if (this.logger != null)
  +	    this.logger.setContainer(this);
   	support.firePropertyChange("logger", oldLogger, this.logger);
   
       }
  @@ -401,6 +405,8 @@
   
   	Manager oldManager = this.manager;
   	this.manager = manager;
  +	if (this.manager != null)
  +	    this.manager.setContainer(this);
   	support.firePropertyChange("manager", oldManager, this.manager);
   
       }
  @@ -494,6 +500,8 @@
   
   	Realm oldRealm = this.realm;
   	this.realm = realm;
  +	if (this.realm != null)
  +	    this.realm.setContainer(this);
   	support.firePropertyChange("realm", oldRealm, this.realm);
   
       }
  @@ -524,6 +532,8 @@
   
   	Resources oldResources = this.resources;
   	this.resources = resources;
  +	if (this.resources != null)
  +	    this.resources.setContainer(this);
   	support.firePropertyChange("resources", oldResources, this.resources);
   
       }
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Catalina.java
  
  Index: Catalina.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Catalina.java,v
1.1 2000/02/13 07:09:31 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/02/13 07:09:31 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat.startup;
  
  
  import java.io.File;
  import java.io.IOException;
  import org.apache.tomcat.util.xml.XmlAction;
  import org.apache.tomcat.util.xml.XmlMapper;
  
  
  /**
   * Startup/Shutdown shell program for Catalina.  The following command line
   * options are recognized:
   * <ul>
   * <li><b>-config {pathname}</b> - Set the pathname of the configuration
file
   *     to be processed [conf/server.xml].
   * <li><b>-help</b> - Display usage information.
   * <li><b>-stop</b> - Stop the currently running instance of Catalina.
   * </u>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/02/13 07:09:31 $
   */
  
  public final class Catalina {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * Pathname to the server configuration file.
       */
      private String configFile = "conf/server.xml";
  
  
      // ----------------------------------------------------------- Main Program
  
  
      /**
       * The application main program.
       *
       * @param args Command line arguments
       */
      public static void main(String args[]) {
  
  	try {
  	    Catalina catalina = new Catalina();
  	    if (catalina.arguments(args))
  		catalina.execute();
  	} catch (Exception e) {
  	    e.printStackTrace();
  	}
  
      }
  
  
      // -------------------------------------------------------- Private Methods
  
  
      /**
       * Process the specified command line arguments, and return
       * <code>true</code> if we should continue processing; otherwise
       * return <code>false</code>.
       *
       * @param args Command line arguments to process
       */
      private boolean arguments(String args[]) {
  
  	boolean isConfig = false;
  
  	for (int i = 0; i < args.length; i++) {
  	    if (isConfig) {
  		configFile = args[i];
  		isConfig = false;
  	    } else if (args[i].equals("-help")) {
  		usage();
  		return (false);
  	    } else {
  		usage();
  	    }
  	}
  
  	return (true);
  
      }
  
  
      /**
       * Create and configure the XmlMapper we will be using.
       */
      private XmlMapper createMapper() {
  
  	// Initialize the mapper
  	XmlMapper mapper = new XmlMapper();
  	mapper.setDebug(999);
  
  	// Configure the actions we will be using
  
  	;	// FIXME -- Adapter or Connector or something!
  
  	mapper.addRule("Engine", mapper.objectCreate("org.apache.tomcat.core.StandardEngine", "className"));
  	mapper.addRule("Engine", mapper.setProperties());
  
  	mapper.addRule("Engine/Host", mapper.objectCreate("org.apache.tomcat.core.StandardHost",
"className"));
  	mapper.addRule("Engine/Host", mapper.setProperties());
  	mapper.addRule("Engine/Host", mapper.addChild("addChild", "org.apache.tomcat.Container"));
  
  	mapper.addRule("Engine/Host/Context", mapper.objectCreate("org.apache.tomcat.core.StandardContext",
"className"));
  	mapper.addRule("Engine/Host/Context", mapper.setProperties());
  	mapper.addRule("Engine/Host/Context", mapper.addChild("addChild", "org.apache.tomcat.Container"));
  	;	// FIXME -- Process web.xml as well!!!
  
  	mapper.addRule("Engine/Host/Context/Loader", mapper.objectCreate("org.apache.tomcat.core.StandardLoader",
"className"));
  	mapper.addRule("Engine/Host/Context/Loader", mapper.setProperties());
  	mapper.addRule("Engine/Host/Context/Loader", mapper.addChild("setLoader", "org.apache.tomcat.Loader"));
  
  	mapper.addRule("Engine/Host/Context/Logger", mapper.objectCreate(null, "className"));
  	mapper.addRule("Engine/Host/Context/Logger", mapper.setProperties());
  	mapper.addRule("Engine/Host/Context/Logger", mapper.addChild("setLogger", "org.apache.tomcat.Logger"));
  
  	mapper.addRule("Engine/Host/Context/Manager", mapper.objectCreate("org.apache.tomcat.session.StandardManager",
"className"));
  	mapper.addRule("Engine/Host/Context/Manager", mapper.setProperties());
  	mapper.addRule("Engine/Host/Context/Manager", mapper.addChild("setManager", "org.apache.tomcat.Manager"));
  
  	mapper.addRule("Engine/Host/Context/Realm", mapper.objectCreate(null, "className"));
  	mapper.addRule("Engine/Host/Context/Realm", mapper.setProperties());
  	mapper.addRule("Engine/Host/Context/Realm", mapper.addChild("setRealm", "org.apache.tomcat.Realm"));
  
  	mapper.addRule("Engine/Host/Context/Resources", mapper.objectCreate("org.apache.tomcat.core.StandardResources",
"className"));
  	mapper.addRule("Engine/Host/Context/Resources", mapper.setProperties());
  	mapper.addRule("Engine/Host/Context/Resources", mapper.addChild("setResources", "org.apache.tomcat.Resources"));
  
  	mapper.addRule("Engine/Host/Context/Valve", mapper.objectCreate(null, "className"));
  	mapper.addRule("Engine/Host/Context/Valve", mapper.setProperties());
  	mapper.addRule("Engine/Host/Context/Valve", mapper.addChild("addValve", "org.apache.tomcat.Valve"));
  
  	mapper.addRule("Engine/Host/Loader", mapper.objectCreate("org.apache.tomcat.core.StandardLoader",
"className"));
  	mapper.addRule("Engine/Host/Loader", mapper.setProperties());
  	mapper.addRule("Engine/Host/Loader", mapper.addChild("setLoader", "org.apache.tomcat.Loader"));
  
  	mapper.addRule("Engine/Host/Logger", mapper.objectCreate(null, "className"));
  	mapper.addRule("Engine/Host/Logger", mapper.setProperties());
  	mapper.addRule("Engine/Host/Logger", mapper.addChild("setLogger", "org.apache.tomcat.Logger"));
  
  	mapper.addRule("Engine/Host/Manager", mapper.objectCreate("org.apache.tomcat.session.StandardManager",
"className"));
  	mapper.addRule("Engine/Host/Manager", mapper.setProperties());
  	mapper.addRule("Engine/Host/Manager", mapper.addChild("setManager", "org.apache.tomcat.Manager"));
  
  	mapper.addRule("Engine/Host/Realm", mapper.objectCreate(null, "className"));
  	mapper.addRule("Engine/Host/Realm", mapper.setProperties());
  	mapper.addRule("Engine/Host/Realm", mapper.addChild("setRealm", "org.apache.tomcat.Realm"));
  
  	mapper.addRule("Engine/Host/Resources", mapper.objectCreate("org.apache.tomcat.core.StandardResources",
"className"));
  	mapper.addRule("Engine/Host/Resources", mapper.setProperties());
  	mapper.addRule("Engine/Host/Resources", mapper.addChild("setResources", "org.apache.tomcat.Resources"));
  
  	mapper.addRule("Engine/Host/Valve", mapper.objectCreate(null, "className"));
  	mapper.addRule("Engine/Host/Valve", mapper.setProperties());
  	mapper.addRule("Engine/Host/Valve", mapper.addChild("addValve", "org.apache.tomcat.Valve"));
  
  	mapper.addRule("Engine/Loader", mapper.objectCreate("org.apache.tomcat.core.StandardLoader",
"className"));
  	mapper.addRule("Engine/Loader", mapper.setProperties());
  	mapper.addRule("Engine/Loader", mapper.addChild("setLoader", "org.apache.tomcat.Loader"));
  
  	mapper.addRule("Engine/Logger", mapper.objectCreate(null, "className"));
  	mapper.addRule("Engine/Logger", mapper.setProperties());
  	mapper.addRule("Engine/Logger", mapper.addChild("setLogger", "org.apache.tomcat.Logger"));
  
  	mapper.addRule("Engine/Manager", mapper.objectCreate("org.apache.tomcat.session.StandardManager",
"className"));
  	mapper.addRule("Engine/Manager", mapper.setProperties());
  	mapper.addRule("Engine/Manager", mapper.addChild("setManager", "org.apache.tomcat.Manager"));
  
  	mapper.addRule("Engine/Realm", mapper.objectCreate(null, "className"));
  	mapper.addRule("Engine/Realm", mapper.setProperties());
  	mapper.addRule("Engine/Realm", mapper.addChild("setRealm", "org.apache.tomcat.Realm"));
  
  	mapper.addRule("Engine/Resources", mapper.objectCreate("org.apache.tomcat.core.StandardResources",
"className"));
  	mapper.addRule("Engine/Resources", mapper.setProperties());
  	mapper.addRule("Engine/Resources", mapper.addChild("setResources", "org.apache.tomcat.Resources"));
  
  	mapper.addRule("Engine/Valve", mapper.objectCreate(null, "className"));
  	mapper.addRule("Engine/Valve", mapper.setProperties());
  	mapper.addRule("Engine/Valve", mapper.addChild("addValve", "org.apache.tomcat.Valve"));
  
  	return (mapper);
  
  	// FIXME - When do we call start() on all of these objects?
  
      }
  
  
      /**
       * Execute the processing that has been configured from the command line.
       */
      private void execute() throws Exception {
  
  	// Configure the XmlMapper we will be using
  	XmlMapper mapper = createMapper();
  
  	// Process the configuration file
  	File file = new File(configFile);
  	mapper.readXml(file, null);
  
  	// Start or stop
  	;	// FIXME
  
      }
  
  
      /**
       * Print usage information for this application.
       */
      private void usage() {
  
  	System.err.println("usage: java org.apache.tomcat.startup.Catalina" +
  			   " [ -config {pathname} | -help | -stop ]");
  
      }
  
  
      // --------------------------------------------------------- Static Methods
  
  
  
  }
  
  
  // ------------------------------------------------------------ Private Classes
  
  
  
  
  

Mime
View raw message