You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2001/07/19 00:46:50 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup BootstrapService.java CatalinaService.java

remm        01/07/18 15:46:50

  Added:       catalina/src/share/org/apache/catalina/startup
                        BootstrapService.java CatalinaService.java
  Log:
  - Add a Bootstrap and a Catalina class which do a synchronous stop operation without
    using a socket (which is a lot more secure, obviously).
  - Still doesn't solve the shutdown problem unfortunately, since Catalina's
    shutdown takes a very long time (without using any CPU time; I still don't know the reason for this), and
    NT will kill the service after about 30s idle. With only one or two
    contexts, the shutdown is faster, and will suceed.
    The error message added to NT's event log is :
    The Jakarta Tomcat service has timed out during a stop request and is being terminated.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/BootstrapService.java
  
  Index: BootstrapService.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/BootstrapService.java,v 1.1 2001/07/18 22:46:50 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2001/07/18 22:46:50 $
   *
   * ====================================================================
   *
   * 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.catalina.startup;
  
  
  import java.io.File;
  import java.io.IOException;
  import java.lang.reflect.Method;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.ArrayList;
  import org.apache.catalina.loader.Extension;
  import org.apache.catalina.loader.StandardClassLoader;
  
  
  /**
   * Special version of the Catalina bootstrap, designed to be invoked with JNI,
   * and designed to allow easier wrapping by system level components, which
   * would otherwise be confused by the asychronous startup and shutdown Catalina
   * uses. This class should be used to run Catalina as a system service under
   * Windows NT and clones.
   *
   * @author Craig R. McClanahan
   * @author Remy Maucherat
   * @version $Revision: 1.1 $ $Date: 2001/07/18 22:46:50 $
   */
  
  public final class BootstrapService {
  
  
      // ------------------------------------------------------- Static Variables
  
  
      /**
       * Debugging detail level for processing the startup.
       */
      private static int debug = 0;
  
  
      /**
       * Catalina instance.
       */
      private static Object catalina = null;
  
  
      // ----------------------------------------------------------- Main Program
  
  
      /**
       * The main program for the bootstrap.
       *
       * @param args Command line arguments to be processed
       */
      public static void main(String args[]) {
  
          // Set the debug flag appropriately
          for (int i = 0; i < args.length; i++)  {
              if ("-debug".equals(args[i]))
                  debug = 1;
          }
  
          try {
          
              if (catalina == null) {
  
                  System.out.println("Create Catalina server");
              
                  // Construct the class loaders we will need
                  ClassLoader commonLoader = createCommonLoader();
                  ClassLoader catalinaLoader = 
                      createCatalinaLoader(commonLoader);
                  ClassLoader sharedLoader = createSharedLoader(commonLoader);
  
                  Thread.currentThread().setContextClassLoader(catalinaLoader);
  
                  // Load our startup class and call its process() method
                  
                  if( System.getSecurityManager() != null ) {
                      // Pre load some classes required for SecurityManager
                      // so that defineClassInPackage does not throw a
                      // security exception.
                      String basePackage = "org.apache.catalina.";
                      catalinaLoader.loadClass
                          (basePackage + 
                           "core.ApplicationContext$PrivilegedGetRequestDispatcher");
                      catalinaLoader.loadClass
                          (basePackage + 
                           "core.ApplicationContext$PrivilegedGetResource");
                      catalinaLoader.loadClass
                          (basePackage + 
                           "core.ApplicationContext$PrivilegedGetResourcePaths");
                      catalinaLoader.loadClass
                          (basePackage + 
                           "core.ApplicationContext$PrivilegedLogMessage");
                      catalinaLoader.loadClass
                          (basePackage + 
                           "core.ApplicationContext$PrivilegedLogException");
                      catalinaLoader.loadClass
                          (basePackage + 
                           "core.ApplicationContext$PrivilegedLogThrowable");
                      catalinaLoader.loadClass
                          (basePackage + 
                           "core.ApplicationDispatcher$PrivilegedForward");
                      catalinaLoader.loadClass
                          (basePackage + 
                           "core.ApplicationDispatcher$PrivilegedInclude");
                      catalinaLoader.loadClass
                          (basePackage + 
                           "connector.HttpRequestBase$PrivilegedGetSession");
                      catalinaLoader.loadClass
                          (basePackage + 
                           "loader.WebappClassLoader$PrivilegedFindResource");
                      catalinaLoader.loadClass
                          (basePackage + "session.StandardSession");
                      catalinaLoader.loadClass
                          (basePackage + "util.CookieTools");
                      catalinaLoader.loadClass(basePackage + "util.Enumerator");
                      catalinaLoader.loadClass("javax.servlet.http.Cookie");
                  }
  
                  // Instantiate a startup class instance
                  if (debug >= 1)
                      log("Loading startup class");
                  Class startupClass =
                      catalinaLoader.loadClass
                      ("org.apache.catalina.startup.CatalinaService");
                  Object startupInstance = startupClass.newInstance();
                  
                  // Set the shared extensions class loader
                  if (debug >= 1)
                      log("Setting startup class properties");
                  String methodName = "setParentClassLoader";
                  Class paramTypes[] = new Class[1];
                  paramTypes[0] = Class.forName("java.lang.ClassLoader");
                  Object paramValues[] = new Object[1];
                  paramValues[0] = sharedLoader;
                  Method method =
                      startupInstance.getClass().getMethod(methodName, paramTypes);
                  method.invoke(startupInstance, paramValues);
                  
                  catalina = startupInstance;
  
              }
  
              // Call the process() method
              if (debug >= 1)
                  log("Calling startup class process() method");
              String methodName = "process";
              Class paramTypes[] = new Class[1];
              paramTypes[0] = args.getClass();
              Object paramValues[] = new Object[1];
              paramValues[0] = args;
              Method method =
                  catalina.getClass().getMethod(methodName, paramTypes);
              method.invoke(catalina, paramValues);
              
          } catch (Exception e) {
              System.out.println("Exception during startup processing");
              e.printStackTrace(System.out);
              System.exit(2);
          }
  
          //System.exit(0);
  
      }
  
  
      /**
       * Construct and return the class loader to be used for loading
       * of the shared system classes.
       */
      private static ClassLoader createCommonLoader() {
  
          if (debug >= 1)
              log("Creating COMMON class loader");
  
          // Check to see if JNDI is already present in the system classpath
          boolean loadJNDI = true;
          try {
              Class.forName("javax.naming.Context");
              loadJNDI = false;
          } catch (ClassNotFoundException e) {
          }
  
          // Construct the "class path" for this class loader
          ArrayList list = new ArrayList();
  
          // Add the "common/classes" directory if it exists
          File classes = new File(System.getProperty("catalina.home"),
                                  "common/classes");
          if (classes.exists() && classes.canRead() &&
              classes.isDirectory()) {
              try {
                  URL url = new URL("file", null,
                                    classes.getCanonicalPath() + "/");
                  if (debug >= 1)
                      log("  Adding " + url.toString());
                  list.add(url.toString());
              } catch (IOException e) {
                  System.out.println("Cannot create URL for " +
                                     classes.getAbsolutePath());
                  e.printStackTrace(System.out);
                  System.exit(1);
              }
          }
  
          // Add all JAR files in the "common/lib" directory if it exists
          File directory = new File(System.getProperty("catalina.home"),
                                    "common/lib");
          if (!directory.exists() || !directory.canRead() ||
              !directory.isDirectory()) {
              System.out.println("Directory " + directory.getAbsolutePath()
                                 + " does not exist");
              System.exit(1);
          }
          String filenames[] = directory.list();
          for (int i = 0; i < filenames.length; i++) {
              String filename = filenames[i].toLowerCase();
              if ((!filename.endsWith(".jar")) ||
                  (filename.indexOf("bootstrap.jar") != -1) ||
                  ((!loadJNDI) && (filename.indexOf("jndi.jar") != -1)))
                  continue;
              File file = new File(directory, filenames[i]);
              try {
                  URL url = new URL("file", null, file.getCanonicalPath());
                  if (debug >= 1)
                      log("  Adding " + url.toString());
                  list.add(url.toString());
              } catch (IOException e) {
                  System.out.println("Cannot create URL for " +
                                     filenames[i]);
                  e.printStackTrace(System.out);
                  System.exit(1);
              }
          }
  
          // Construct the class loader itself
          String array[] = (String[]) list.toArray(new String[list.size()]);
          StandardClassLoader loader = new StandardClassLoader(array);
  
          return (loader);
  
      }
  
  
      /**
       * Construct and return the class loader to be used for loading
       * Catalina internal classes.
       */
      private static ClassLoader createCatalinaLoader(ClassLoader parent) {
  
          if (debug >= 1)
              log("Creating CATALINA class loader");
  
          // Construct the "class path" for this class loader
          ArrayList list = new ArrayList();
  
          // Add the "server/classes" directory if it exists
          File classes = new File(System.getProperty("catalina.home"),
                                  "server/classes");                  
          if (classes.exists() && classes.canRead() &&                
              classes.isDirectory()) {                
              try {                                   
                  URL url = new URL("file", null,
                                    classes.getCanonicalPath() + "/");
                  if (debug >= 1)
                      log("  Adding " + url.toString());
                  list.add(url.toString());
              } catch (IOException e) {
                  System.out.println("Cannot create URL for " +
                                     classes.getAbsolutePath());
                  e.printStackTrace(System.out);
                  System.exit(1);
              }   
          }
  
          // Add all JAR files in the "server/lib" directory if it exists
          File directory = new File(System.getProperty("catalina.home"),
                                    "server/lib");
          if (!directory.exists() || !directory.canRead() ||
              !directory.isDirectory()) {
              System.out.println("Directory " + directory.getAbsolutePath()
                                 + " does not exist");
              System.exit(1);
          }
  	String filenames[] = directory.list();
  	for (int i = 0; i < filenames.length; i++) {
  	    if (!filenames[i].toLowerCase().endsWith(".jar"))
  		continue;
              File file = new File(directory, filenames[i]);
              try {
                  URL url = new URL("file", null, file.getCanonicalPath());
                  if (debug >= 1)
                      log("  Adding " + url.toString());
                  list.add(url.toString());
              } catch (IOException e) {
                  System.out.println("Cannot create URL for " +
                                     filenames[i]);
                  e.printStackTrace(System.out);
                  System.exit(1);
              }
  	}
  
          // Construct the class loader itself
          String array[] = (String[]) list.toArray(new String[list.size()]);
          StandardClassLoader loader = new StandardClassLoader(array, parent);
  
          return (loader);
  
      }
  
  
      /**
       * Construct and return the class loader to be used for shared
       * extensions by web applications loaded with Catalina.
       */
      private static ClassLoader createSharedLoader(ClassLoader parent) {
  
          if (debug >= 1)
              log("Creating SHARED class loader");
  
          // Construct the "class path" for this class loader
          ArrayList list = new ArrayList();
  
          // Add the "classes" directory if it exists
          File classes = new File(System.getProperty("catalina.home"),
                                  "classes");                         
          if (classes.exists() && classes.canRead() &&                
              classes.isDirectory()) {                
              try {                                   
                  URL url = new URL("file", null,
                                    classes.getCanonicalPath() + "/");
                  if (debug >= 1)                                     
                      log("  Adding " + url.toString());              
                  list.add(url.toString());             
              } catch (IOException e) {                 
                  System.out.println("Cannot create URL for " +
                                     classes.getAbsolutePath());
                  e.printStackTrace(System.out);                
                  System.exit(1);                               
              }                                 
          }
  
          // Add all JAR files in the "lib" directory if it exists
          File directory = new File(System.getProperty("catalina.home"),
                                    "lib");
          if (!directory.exists() || !directory.canRead() ||
              !directory.isDirectory()) {
              System.out.println("Directory " + directory.getAbsolutePath()
                                 + " does not exist");
              System.exit(1);
          }
  	String filenames[] = directory.list();
  	for (int i = 0; i < filenames.length; i++) {
  	    if (!filenames[i].toLowerCase().endsWith(".jar"))
  		continue;
              File file = new File(directory, filenames[i]);
              try {
                  URL url = new URL("file", null, file.getCanonicalPath());
                  if (debug >= 1)
                      log("  Adding " + url.toString());
                  list.add(url.toString());
              } catch (IOException e) {
                  System.out.println("Cannot create URL for " +
                                     filenames[i]);
                  e.printStackTrace(System.out);
                  System.exit(1);
              }
  	}
  
          // Construct the class loader itself
          String array[] = (String[]) list.toArray(new String[list.size()]);
          StandardClassLoader loader = new StandardClassLoader(array, parent);
  
          /*
          System.out.println("AVAILABLE OPTIONAL PACKAGES:");
          Extension available[] = loader.findAvailable();
          for (int i = 0; i < available.length; i++)
              System.out.println(available[i].toString());
          System.out.println("REQUIRED OPTIONAL PACKAGES:");
          Extension required[] = loader.findRequired();
          for (int i = 0; i < required.length; i++)
              System.out.println(required[i].toString());
          System.out.println("===========================");
          */
  
          return (loader);
  
      }
  
  
      /**
       * Log a debugging detail message.
       *
       * @param message The message to be logged
       */
      private static void log(String message) {
  
          System.out.print("Bootstrap: ");
          System.out.println(message);
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/CatalinaService.java
  
  Index: CatalinaService.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/CatalinaService.java,v 1.1 2001/07/18 22:46:50 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2001/07/18 22:46:50 $
   *
   * ====================================================================
   *
   * 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.catalina.startup;
  
  
  import java.io.File;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Constructor;
  import java.net.Socket;
  import java.security.Security;
  import java.util.Stack;
  import org.apache.catalina.Container;
  import org.apache.catalina.Lifecycle;
  import org.apache.catalina.LifecycleException;
  import org.apache.catalina.LifecycleListener;
  import org.apache.catalina.Server;
  import org.apache.catalina.Loader;
  import org.apache.catalina.util.xml.SaxContext;
  import org.apache.catalina.util.xml.XmlAction;
  import org.apache.catalina.util.xml.XmlMapper;
  import org.xml.sax.AttributeList;
  
  
  /**
   * 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.  If a relative path is specified, it will be
   *     interpreted as relative to the directory pathname specified by the
   *     "catalina.home" system property.   [conf/server.xml]
   * <li><b>-help</b> - Display usage information.
   * <li><b>-stop</b> - Stop the currently running instance of Catalina.
   * </ul>
   * Special version of the Catalina bootstrap, designed to be invoked with JNI,
   * and designed to allow easier wrapping by system level components, which
   * would otherwise be confused by the asychronous startup and shutdown Catalina
   * uses. This class should be used to run Catalina as a system service under
   * Windows NT and clones.
   *
   * @author Craig R. McClanahan
   * @author Remy Maucherat
   * @version $Revision: 1.1 $ $Date: 2001/07/18 22:46:50 $
   */
  
  public class CatalinaService extends Catalina {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      // ------------------------------------------------------ Protected 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
       */
      protected boolean arguments(String args[]) {
  
  	boolean isConfig = false;
  
          if (args.length < 1) {
              usage();
              return (false);
          }
  
  	for (int i = 0; i < args.length; i++) {
  	    if (isConfig) {
  		configFile = args[i];
  		isConfig = false;
  	    } else if (args[i].equals("-config")) {
  	        isConfig = true;
  	    } else if (args[i].equals("-debug")) {
  		debug = true;
  	    } else if (args[i].equals("-nonaming")) {
  		useNaming = false;
  	    } else if (args[i].equals("-help")) {
  		usage();
  		return (false);
  	    } else if (args[i].equals("start")) {
  	        starting = true;
                  stopping = false;
  	    } else if (args[i].equals("stop")) {
  	        starting = false;
  	        stopping = true;
  	    } else {
  		usage();
                  return (false);
  	    }
  	}
  
  	return (true);
  
      }
  
  
      /**
       * Start a new server instance.
       */
      protected void start() {
  
          // Create and execute our mapper
          XmlMapper mapper = createStartMapper();
  	File file = configFile();
  	try {
  	    mapper.readXml(file, this);
  	} catch (InvocationTargetException e) {
  	    System.out.println("Catalina.start: InvocationTargetException");
  	    e.getTargetException().printStackTrace(System.out);
  	} catch (Exception e) {
  	    System.out.println("Catalina.start: " + e);
  	    e.printStackTrace(System.out);
  	    System.exit(1);
  	}
  
          // Setting additional variables
          if (!useNaming) {
              System.setProperty("catalina.useNaming", "false");
          } else {
              System.setProperty("catalina.useNaming", "true");
              String value = "org.apache.naming";
              String oldValue =
                  System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
              if (oldValue != null) {
                  value = value + ":" + oldValue;
              }
              System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);
              System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
                                 "org.apache.naming.java.javaURLContextFactory");
          }
  
  	// If a SecurityManager is being used, set properties for
  	// checkPackageAccess() and checkPackageDefinition
  	if( System.getSecurityManager() != null ) {
  	    String access = Security.getProperty("package.access");
  	    if( access != null && access.length() > 0 )
  		access += ",";
  	    else
  		access = "sun.,";
  	    Security.setProperty("package.access",
  		access + "org.apache.catalina.,org.apache.jasper.");
  	    String definition = Security.getProperty("package.definition");
  	    if( definition != null && definition.length() > 0 )
  		definition += ",";
  	    else
  		definition = "sun.,";
  	    Security.setProperty("package.definition",
  		// FIX ME package "javax." was removed to prevent HotSpot
  		// fatal internal errors
  		definition + "java.,org.apache.catalina.,org.apache.jasper.");
  	}
  
  	// Start the new server
  	if (server instanceof Lifecycle) {
  	    try {
  	        ((Lifecycle) server).start();
  	    } catch (LifecycleException e) {
  	        System.out.println("Catalina.start: " + e);
  		e.printStackTrace(System.out);
                  if (e.getThrowable() != null) {
                      System.out.println("----- Root Cause -----");
                      e.getThrowable().printStackTrace(System.out);
                  }
  	    }
  	}
  
      }
  
  
      /**
       * Stop an existing server instance.
       */
      protected void stop() {
  
  	// Shut down the server
  	if (server instanceof Lifecycle) {
              try {
  	        ((Lifecycle) server).stop();
  	    } catch (LifecycleException e) {
  	        System.out.println("Catalina.stop: " + e);
  	        e.printStackTrace(System.out);
                  if (e.getThrowable() != null) {
                      System.out.println("----- Root Cause -----");
                      e.getThrowable().printStackTrace(System.out);
                  }
  	    }
  	}
  
          System.out.println("Stop server complete");
          
      }
  
  
  }