tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/task StopTomcat.java
Date Fri, 23 Jun 2000 01:22:00 GMT
costin      00/06/22 18:21:59

  Modified:    src/share/org/apache/tomcat/resources
                        LocalStrings.properties LocalStrings_es.properties
               src/share/org/apache/tomcat/startup Tomcat.java
  Added:       src/share/org/apache/tomcat/task StopTomcat.java
  Log:
  - In Tomcat.java - made StopTomcat an independent task, that can be used outside
  the simple starter.
  
  - Also, generateConfig is a method that can be called from outside. We should make config
  generation optional.
  
  - moved string resources to tomcat.resources
  
  Revision  Changes    Path
  1.2       +10 -1     jakarta-tomcat/src/share/org/apache/tomcat/resources/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/resources/LocalStrings.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalStrings.properties	2000/06/22 23:59:30	1.1
  +++ LocalStrings.properties	2000/06/23 01:21:54	1.2
  @@ -1,4 +1,4 @@
  -# $Id: LocalStrings.properties,v 1.1 2000/06/22 23:59:30 costin Exp $
  +# $Id: LocalStrings.properties,v 1.2 2000/06/23 01:21:54 costin Exp $
   #
   
   # Localized strings for package org.apache.tomcat.core
  @@ -19,3 +19,12 @@
   defaulterrorpage.documentmoved=Document moved
   defaulterrorpage.thisdocumenthasmoved=This document has moved
   defaulterrorpage.internalservleterror=Internal Servlet Error:
  +
  +#Tomcat.java
  +tomcat.usage=usage: 
  +tomcat.start=Starting tomcat. Check logs/tomcat.log for error messages 
  +tomcat.fatalconfigerror=FATAL: configuration error
  +tomcat.nohome=No tomcat.home property, you need to set TOMCAT_HOME or add -Dtomcat.home
  +tomcat.wrongargs=Wrong arguments
  +tomcat.stop=Stop tomcat
  +tomcat.fatal=FATAL:
  \ No newline at end of file
  
  
  
  1.2       +9 -1      jakarta-tomcat/src/share/org/apache/tomcat/resources/LocalStrings_es.properties
  
  Index: LocalStrings_es.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/resources/LocalStrings_es.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalStrings_es.properties	2000/06/22 23:59:31	1.1
  +++ LocalStrings_es.properties	2000/06/23 01:21:56	1.2
  @@ -1,4 +1,4 @@
  -# $Id: LocalStrings_es.properties,v 1.1 2000/06/22 23:59:31 costin Exp $
  +# $Id: LocalStrings_es.properties,v 1.2 2000/06/23 01:21:56 costin Exp $
   #
   
   # Localized strings for package org.apache.tomcat.core
  @@ -18,3 +18,11 @@
   defaulterrorpage.documentmoved=Documento trasladado
   defaulterrorpage.thisdocumenthasmoved=Este Documento ha sido trasladado
   defaulterrorpage.internalservleterror=Error interno del servlet:
  +
  +tomcat.usage=uso: 
  +tomcat.start=Iniciando tomcat. Comprueba el archivo logs/tomcat.log si hay errores
  +tomcat.fatalconfigerror=FATAL: error de configuracion
  +tomcat.nohome=No existe la propiedad tomcat.home, necesitas crear la variable del entorno
TOMCAT_HOME o usar -Dtomcat.home=/ruta/a/tomcat
  +tomcat.wrongargs=Argumentos no validos
  +tomcat.stop=Parando tomcat
  +tomcat.fatal=FATAL:
  \ No newline at end of file
  
  
  
  1.31      +92 -96    jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java
  
  Index: Tomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- Tomcat.java	2000/06/16 17:08:57	1.30
  +++ Tomcat.java	2000/06/23 01:21:57	1.31
  @@ -12,10 +12,6 @@
   import org.apache.tomcat.core.*;
   import org.xml.sax.*;
   
  -// Used to stop tomcat
  -import org.apache.tomcat.service.PoolTcpConnector;
  -import org.apache.tomcat.service.connector.Ajp12ConnectionHandler;
  -
   /**
    * Starter for Tomcat using XML.
    * Based on Ant.
  @@ -23,54 +19,46 @@
    * @author costin@dnt.ro
    */
   public class Tomcat {
  -
  -    private static StringManager sm = StringManager.getManager("org.apache.tomcat.startup");
   
  +    private static StringManager sm =
  +	StringManager.getManager("org.apache.tomcat.resources");
   
  -    static {
  -	// XXX temp fix for wars
  -	// Register our protocols XXX
  -	String warPackage = "org.apache.tomcat.protocol";
  -	String protocolKey = "java.protocol.handler.pkgs";
  -	String protocolHandlers = System.getProperties().getProperty(protocolKey);
  -	System.getProperties().put(protocolKey,
  -				   (protocolHandlers == null) ?
  -				   warPackage : protocolHandlers + "|" + warPackage);
  -    };
  -
       Tomcat() {
       }
   
       // Set the mappings
       void setHelper( XmlMapper xh ) {
  - 	// xh.addRule( "ContextManager", xh.objectCreate("org.apache.tomcat.core.ContextManager")
);
   	xh.addRule( "ContextManager", xh.setProperties() );
  -	//	xh.addRule( "ContextManager", xh.setParent(
  -	//	"setServer" ) ); xh.addRule( "ContextManager",
  -	//	xh.addChild( "setContextManager", null) );
  -
  -	xh.addRule( "ContextManager/ContextInterceptor", xh.objectCreate(null, "className"));
  -	xh.addRule( "ContextManager/ContextInterceptor", xh.setProperties() );
  -	xh.addRule( "ContextManager/ContextInterceptor", xh.setParent("setContextManager") );
  -	xh.addRule( "ContextManager/ContextInterceptor", xh.addChild( "addContextInterceptor",
  -								      "org.apache.tomcat.core.ContextInterceptor" ) );
  -
  -	xh.addRule( "ContextManager/RequestInterceptor", xh.objectCreate(null, "className"));
  -	xh.addRule( "ContextManager/RequestInterceptor", xh.setProperties() );
  -	xh.addRule( "ContextManager/RequestInterceptor", xh.setParent("setContextManager") );
  -	xh.addRule( "ContextManager/RequestInterceptor", xh.addChild( "addRequestInterceptor",
  -								      "org.apache.tomcat.core.RequestInterceptor" ) );
  +
  +	xh.addRule( "ContextManager/ContextInterceptor",
  +		    xh.objectCreate(null, "className"));
  +	xh.addRule( "ContextManager/ContextInterceptor",
  +		    xh.setProperties() );
  +	xh.addRule( "ContextManager/ContextInterceptor",
  +		    xh.setParent("setContextManager") );
  +	xh.addRule( "ContextManager/ContextInterceptor",
  +		    xh.addChild( "addContextInterceptor",
  +				 "org.apache.tomcat.core.ContextInterceptor"));
  +
  +	xh.addRule( "ContextManager/RequestInterceptor",
  +		    xh.objectCreate(null, "className"));
  +	xh.addRule( "ContextManager/RequestInterceptor",
  +		    xh.setProperties() );
  +	xh.addRule( "ContextManager/RequestInterceptor",
  +		    xh.setParent("setContextManager") );
  +	xh.addRule( "ContextManager/RequestInterceptor",
  +		    xh.addChild( "addRequestInterceptor",
  +				 "org.apache.tomcat.core.RequestInterceptor"));
   
   	// Default host
  - 	xh.addRule( "ContextManager/Context", xh.objectCreate("org.apache.tomcat.core.Context"));
  -	xh.addRule( "ContextManager/Context", xh.setParent( "setContextManager") );
  -	xh.addRule( "ContextManager/Context", xh.setProperties() );
  -//         // Rules for setting Context SecurityManager Permissions
  -//         xh.addRule( "ContextManager/Context/Permission",xh.methodSetter("setPermission",3));
  -//         xh.addRule( "ContextManager/Context/Permission",xh.methodParam(0,"className"));
  -//         xh.addRule( "ContextManager/Context/Permission",xh.methodParam(1,"attribute"));
  -//         xh.addRule( "ContextManager/Context/Permission",xh.methodParam(2,"value"));
  -	xh.addRule( "ContextManager/Context", xh.addChild( "addContext", null ) );
  + 	xh.addRule( "ContextManager/Context",
  +		    xh.objectCreate("org.apache.tomcat.core.Context"));
  +	xh.addRule( "ContextManager/Context",
  +		    xh.setParent( "setContextManager") );
  +	xh.addRule( "ContextManager/Context",
  +		    xh.setProperties() );
  +	xh.addRule( "ContextManager/Context",
  +		    xh.addChild( "addContext", null ) );
   
   	// Virtual host support.
   	// Push a host object on the stack
  @@ -98,43 +86,53 @@
   	    });
   	xh.addRule( "ContextManager/Host", xh.setProperties());
   	
  - 	xh.addRule( "ContextManager/Host/Context", xh.objectCreate("org.apache.tomcat.core.Context"));
  -	xh.addRule( "ContextManager/Host/Context", xh.setProperties() );
  + 	xh.addRule( "ContextManager/Host/Context",
  +		    xh.objectCreate("org.apache.tomcat.core.Context"));
  +	xh.addRule( "ContextManager/Host/Context",
  +		    xh.setProperties() );
   	xh.addRule( "ContextManager/Host/Context", new XmlAction() {
   		public void end( SaxContext ctx) throws Exception {
   		    Stack st=ctx.getObjectStack();
   		    
   		    Context tcCtx=(Context)st.pop(); // get the Context
   		    HostConfig hc=(HostConfig)st.peek();
  -		    st.push( tcCtx ); // put back the context, to be cleaned up corectly
  -
  +		    st.push( tcCtx );
  +		    // put back the context, to be cleaned up corectly
  +		    
   		    hc.addContext( tcCtx );
   		}
   	    });
  -
       }
   
       void setConnectorHelper( XmlMapper xh ) {
  -
  -	xh.addRule( "ContextManager/Connector", xh.objectCreate(null, "className"));
  -	xh.addRule( "ContextManager/Connector", xh.setParent( "setServer", "java.lang.Object")
);
  -	xh.addRule( "ContextManager/Connector", xh.addChild( "addServerConnector", "org.apache.tomcat.core.ServerConnector")
);
  -
  -	xh.addRule( "ContextManager/Connector/Parameter", xh.methodSetter("setProperty",2) );
  -	xh.addRule( "ContextManager/Connector/Parameter", xh.methodParam(0, "name") );
  -	xh.addRule( "ContextManager/Connector/Parameter", xh.methodParam(1, "value") );
  +	xh.addRule( "ContextManager/Connector",
  +		    xh.objectCreate(null, "className"));
  +	xh.addRule( "ContextManager/Connector",
  +		    xh.setParent( "setServer", "java.lang.Object") );
  +	xh.addRule( "ContextManager/Connector",
  +		    xh.addChild( "addServerConnector",
  +				 "org.apache.tomcat.core.ServerConnector") );
  +
  +	xh.addRule( "ContextManager/Connector/Parameter",
  +		    xh.methodSetter("setProperty",2) );
  +	xh.addRule( "ContextManager/Connector/Parameter",
  +		    xh.methodParam(0, "name") );
  +	xh.addRule( "ContextManager/Connector/Parameter",
  +		    xh.methodParam(1, "value") );
       }
   
   
  -    /** Setup loggers when reading the configuration file - this will be called only when
  -     *  starting tomcat as deamon, all other modes will output to stderr
  -    */
  +    /** Setup loggers when reading the configuration file - this will be
  +     *  called only when starting tomcat as deamon, all other modes will
  +     * output to stderr
  +     */
       void setLogHelper( XmlMapper xh ) {
   	xh.addRule("Server/Logger",
   		   xh.objectCreate("org.apache.tomcat.logging.TomcatLogger"));
   	xh.addRule("Server/Logger", xh.setProperties());
   	xh.addRule("Server/Logger", 
  -		   xh.addChild("addLogger", "org.apache.tomcat.logging.Logger") );
  +		   xh.addChild("addLogger",
  +			       "org.apache.tomcat.logging.Logger") );
       }
   
       /**
  @@ -143,8 +141,8 @@
        * used, the default configuration filename will be loaded from
        * the TOMCAT_HOME directory.
        *
  -     * If a relative config file is used, it will be relative to the current working
  -     * directory.
  +     * If a relative config file is used, it will be relative to the current
  +     * working directory.
        *
        * @param cm The ContextManager we are configuring
        **/
  @@ -157,7 +155,8 @@
   	String tchome = System.getProperty("tomcat.home");
   	if (tchome == null) {
   	    System.out.println(sm.getString("tomcat.nohome"));
  -	    tchome = ".";	// Assume current working directory
  +	    tchome = ".";
  +	    // Assume current working directory
   	}
   	// Home will be identical to tomcat home if default config is used.
   	cm.setInstallDir(tchome);
  @@ -194,24 +193,42 @@
   	    System.exit(1);
   	}
   
  +	System.out.println(sm.getString("tomcat.start"));
  +	cm.init(); // set up contexts
  +
  +	// XXX Make this optional, and make sure it doesn't require
  +	// a full start. It is called after init to make sure
  +	// auto-configured contexts are initialized.
  +	generateServerConfig( cm );
  +
  +	cm.start(); // start serving
  +    }
  +
  +    /** This method will generate Server config files that
  +	reflect the existing cm settings. It is called
  +	at startup, and may be called when a new context is
  +	added ( at runtime for example ).
  +    */
  +    public static void generateServerConfig( ContextManager cm )
  +	throws TomcatException
  +    {
   	// Generate Apache configs
   	//
  -	org.apache.tomcat.task.ApacheConfig apacheConfig=new  org.apache.tomcat.task.ApacheConfig();
  +	org.apache.tomcat.task.ApacheConfig apacheConfig=
  +	    new  org.apache.tomcat.task.ApacheConfig();
   	apacheConfig.execute( cm );     
   
   	// Generate IIS configs
   	//
  -	org.apache.tomcat.task.IISConfig iisConfig=new  org.apache.tomcat.task.IISConfig();
  +	org.apache.tomcat.task.IISConfig iisConfig=
  +	    new  org.apache.tomcat.task.IISConfig();
   	iisConfig.execute( cm );     
   
   	// Generate Netscape configs
   	//
  -	org.apache.tomcat.task.NSConfig nsConfig=new  org.apache.tomcat.task.NSConfig();
  +	org.apache.tomcat.task.NSConfig nsConfig=
  +	    new  org.apache.tomcat.task.NSConfig();
   	nsConfig.execute( cm );     
  -
  -	System.out.println(sm.getString("tomcat.start"));
  -	cm.init(); // set up contexts
  -	cm.start(); // start serving
       }
       
       public static void main(String args[] ) {
  @@ -233,7 +250,7 @@
        *  that will change when we add real callbacks ( it's equivalent
        *  with the previous RMI method from almost all points of view )
        */
  -    void stopTomcat() {
  +    void stopTomcat() throws TomcatException {
   	XmlMapper xh=new XmlMapper();
   	xh.setDebug( 0 );
   	ContextManager cm=new ContextManager();
  @@ -245,33 +262,11 @@
   	    System.out.println(sm.getString("tomcat.fatalconfigerror") );
   	    ex.printStackTrace();
   	    System.exit(1);
  -	}
  -
  -	// Find Ajp12 connector
  -	int portInt=8007;
  -	Enumeration enum=cm.getConnectors();
  -	while( enum.hasMoreElements() ) {
  -	    Object con=enum.nextElement();
  -	    if( con instanceof  PoolTcpConnector ) {
  -		PoolTcpConnector tcpCon=(PoolTcpConnector) con;
  -		if( tcpCon.getTcpConnectionHandler()  instanceof Ajp12ConnectionHandler ) {
  -		    portInt=tcpCon.getPort();
  -		}
  -	    }
  -	}
  -
  -	// use Ajp12 to stop the server...
  -	try {
  -	    Socket socket = new Socket("localhost", portInt);
  -	    OutputStream os=socket.getOutputStream();
  -	    byte stopMessage[]=new byte[2];
  -	    stopMessage[0]=(byte)254;
  -	    stopMessage[1]=(byte)15;
  -	    os.write( stopMessage );
  -	    socket.close();
  -	} catch(Exception ex ) {
  -	    ex.printStackTrace();
   	}
  +	
  +	org.apache.tomcat.task.StopTomcat stopTc=
  +	    new  org.apache.tomcat.task.StopTomcat();
  +	stopTc.execute( cm );     
       }
       
       // -------------------- Command-line args processing --------------------
  @@ -279,6 +274,7 @@
       String configFile=null;
       // relative to TOMCAT_HOME 
       static final String DEFAULT_CONFIG="conf/server.xml";
  +
       boolean doStop=false;
       
       public static void printUsage() {
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/task/StopTomcat.java
  
  Index: StopTomcat.java
  ===================================================================
  /*
   * ====================================================================
   *
   * 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.task;
  
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.util.*;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.servlet.http.*;
  
  // Used to stop tomcat
  import org.apache.tomcat.service.PoolTcpConnector;
  import org.apache.tomcat.service.connector.Ajp12ConnectionHandler;
  
  /**
   * This task will stop tomcat
   *
   * @author Costin Manolache
   */
  public class StopTomcat { 
  
      public StopTomcat() 
      {
      }
  
      /** This particular implementation will search for an AJP12
  	connector ( that have a special stop command ).
      */
      public void execute(ContextManager cm)
  	throws TomcatException 
      {
  	// Find Ajp12 connector
  	int portInt=8007;
  	Enumeration enum=cm.getConnectors();
  	while( enum.hasMoreElements() ) {
  	    Object con=enum.nextElement();
  	    if( con instanceof  PoolTcpConnector ) {
  		PoolTcpConnector tcpCon=(PoolTcpConnector) con;
  		if( tcpCon.getTcpConnectionHandler()
  		    instanceof Ajp12ConnectionHandler ) {
  		    portInt=tcpCon.getPort();
  		}
  	    }
  	}
  
  	// use Ajp12 to stop the server...
  	try {
  	    Socket socket = new Socket("localhost", portInt);
  	    OutputStream os=socket.getOutputStream();
  	    byte stopMessage[]=new byte[2];
  	    stopMessage[0]=(byte)254;
  	    stopMessage[1]=(byte)15;
  	    os.write( stopMessage );
  	    socket.close();
  	} catch(Exception ex ) {
  	    ex.printStackTrace();
  	}
      }
      
  }
  
  
  

Mime
View raw message