You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/09/17 09:52:45 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/task StartTomcat.java

costin      00/09/17 00:52:45

  Modified:    src/share/org/apache/tomcat/startup Main.java Tomcat.java
               src/share/org/apache/tomcat/task StartTomcat.java
  Log:
  - made generation of apache config files optional.
  XXX document it after it's tested and agreed
  
  - fixes for recent commits
  
  Revision  Changes    Path
  1.10      +9 -7      jakarta-tomcat/src/share/org/apache/tomcat/startup/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Main.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Main.java	2000/09/17 06:46:53	1.9
  +++ Main.java	2000/09/17 07:52:44	1.10
  @@ -243,12 +243,14 @@
   
   	    // add CLASSPATH
   	    String cpath=System.getProperty( "tomcat.cp");
  -	    System.out.println("Extra CLASSPATH: " + cpath);
  -	    String pathSep=System.getProperty( "path.separator");
  -	    StringTokenizer st=new StringTokenizer( cpath, pathSep );
  -	    while( st.hasMoreTokens() ) {
  -		String path=st.nextToken();
  -		urlV.addElement( getURL( path, "" ));
  +	    if( cpath!=null ) {
  +		System.out.println("Extra CLASSPATH: " + cpath);
  +		String pathSep=System.getProperty( "path.separator");
  +		StringTokenizer st=new StringTokenizer( cpath, pathSep );
  +		while( st.hasMoreTokens() ) {
  +		    String path=st.nextToken();
  +		    urlV.addElement( getURL( path, "" ));
  +		}
   	    }
   
   	    // Add tools.jar if JDK1.2
  @@ -340,7 +342,7 @@
          boolean task;
          }
       */
  -    String args0[]= { "help", "stop" };
  +    String args0[]= { "help", "stop", "g", "generateConfigs" };
       String args1[]= { "f", "config", "h", "home" };
   
       /** Read command line arguments and set properties in proxy,
  
  
  
  1.41      +5 -1      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.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- Tomcat.java	2000/08/27 20:37:32	1.40
  +++ Tomcat.java	2000/09/17 07:52:44	1.41
  @@ -56,12 +56,13 @@
   	}
   
   	StartTomcat st=new StartTomcat();
  +	if( doGenerate ) st.setGenerateConfigs( true );
   
   	// load server.xml
   	if( configFile!=null)
   	    st.setConfig( configFile );
   	
  -	st.startTomcat();
  +	st.execute();
       }
       
       public static void main(String args[] ) {
  @@ -83,6 +84,7 @@
       static final String DEFAULT_CONFIG="conf/server.xml";
   
       boolean doStop=false;
  +    boolean doGenerate=false;
       
       public static void printUsage() {
   	System.out.println(sm.getString("tomcat.usage"));
  @@ -100,6 +102,8 @@
   		
   	    } else if (arg.equals("-stop")) {
   		doStop=true;
  +	    } else if (arg.equals("-g") || arg.equals("-generateConfigs")) {
  +		doGenerate=true;
   	    } else if (arg.equals("-f") || arg.equals("-config")) {
   		i++;
   		if( i < args.length )
  
  
  
  1.4       +132 -21   jakarta-tomcat/src/share/org/apache/tomcat/task/StartTomcat.java
  
  Index: StartTomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/task/StartTomcat.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StartTomcat.java	2000/08/30 05:15:39	1.3
  +++ StartTomcat.java	2000/09/17 07:52:44	1.4
  @@ -107,10 +107,33 @@
   	    task.execute();     
   	    return;
   	}
  -	startTomcat();
  +
  +	ContextManager cm=prepareContextManager();
  +	
  +	// 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.
  +	if( doGenerateConfigs ) {
  +	    generateServerConfig( cm );
  +	    return;
  +	}
  +
  +	try {
  +	    cm.start(); // start serving
  +	}
  +	catch (java.net.BindException be) {
  +	    loghelper.log("Starting Tomcat: " + be.getMessage(), Logger.ERROR);
  +	    System.out.println(sm.getString("tomcat.bindexception"));
  +	    try {
  +		cm.stop();
  +	    }
  +	    catch (Exception e) {
  +		loghelper.log("Stopping ContextManager", e);
  +	    }
  +	}
       }
   
  -    public void startTomcat() throws Exception {
  +    public ContextManager prepareContextManager() throws Exception {
   	XmlMapper xh=new XmlMapper();
   	xh.setDebug( 0 );
   	ContextManager cm=new ContextManager();
  @@ -151,25 +174,8 @@
   	System.out.println(sm.getString("tomcat.start", new Object[] { path }));
   	
   	cm.init(); // set up contexts
  -	loghelper.log(Constants.TOMCAT_NAME + " " + Constants.TOMCAT_VERSION);	
  -
  -	// 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 );
  -	try {
  -	    cm.start(); // start serving
  -	}
  -	catch (java.net.BindException be) {
  -	    loghelper.log("Starting Tomcat: " + be.getMessage(), Logger.ERROR);
  -	    System.out.println(sm.getString("tomcat.bindexception"));
  -	    try {
  -		cm.stop();
  -	    }
  -	    catch (Exception e) {
  -		loghelper.log("Stopping ContextManager", e);
  -	    }
  -	}
  +	loghelper.log(Constants.TOMCAT_NAME + " " + Constants.TOMCAT_VERSION);
  +	return cm;
       }
   
       /** Special call to support a multiple class paths
  @@ -250,6 +256,9 @@
   	} else if( "config".equals( n ) ||
   		   "f".equals(n) ) {
   	    setConfig( (String)v);
  +	} else if( "generateConfigs".equals( n ) ||
  +		   "g".equals(n) ) {
  +	    setGenerateConfigs( true );
   	} else if( "home".equals( n ) ||
   		   "h".equals(n)) {
   	    setHome( (String)v);
  @@ -261,9 +270,17 @@
       String configFile=null;
       boolean doHelp=false;
       boolean doStop=false;
  +    boolean doGenerateConfigs=false;
       // relative to TOMCAT_HOME 
       static final String DEFAULT_CONFIG="conf/server.xml";
   
  +    public void setGenerateConfigs( boolean b ) {
  +	doGenerateConfigs=b;
  +    }
  +
  +    public void setG( boolean b ) {
  +	doGenerateConfigs=b;
  +    }
   
       /** Print help message
        */
  @@ -298,4 +315,98 @@
       }
   
   
  +    // -------------------- Command-line based startup
  +    /** Originally part of JNI endpoint
  +     */
  +    public int startup(String cmdLine,
  +		       String stdout,
  +		       String stderr)
  +    {
  +        try {
  +            if(null != stdout) {
  +                System.setOut(new PrintStream(new FileOutputStream(stdout)));
  +            }
  +            if(null != stderr) {
  +                System.setErr(new PrintStream(new FileOutputStream(stderr)));
  +            }
  +        } catch(Throwable t) {
  +        }
  +	
  +	// We need to make sure tomcat did start successfully and
  +	// report this back.
  +        try {
  +            StartupThread startup = new StartupThread(cmdLine);
  +            startup.start();
  +	    System.out.println("Starting up StartupThread");
  +            synchronized (this) {
  +                wait(60*1000);
  +            }
  +	    System.out.println("End waiting");
  +        } catch(Throwable t) {
  +        }
  +
  +        if(running) {
  +	    System.out.println("Running fine ");
  +            return 1;
  +        }
  +	System.out.println("Error - why doesn't run ??");
  +        return 0;
  +    }
  +
  +    boolean running = false;
  +    
  +    // Called back when the server is initializing the handler
  +    public void startNotify(Object handler) {
  +	// the handler is no longer useable
  +    	if( handler==null ) {
  +	    running=false;
  +	    notify();
  +	    return;
  +	}
  +
  +	System.out.println("Running ...");
  +	running=true;
  +        notify();
  +    }
  +}
  +
  +/** Tomcat is started in a separate thread. It may be loaded on demand,
  +    and we can't take up the request thread, as it may be affect the server.
  +
  +    During startup the JNIConnectionHandler will be initialized and
  +    will configure JNIEndpoint ( static - need better idea )
  + */
  +class StartupThread extends Thread {
  +    String []cmdLine = null;
  +
  +    public StartupThread(String cmdLine) {
  +
  +        if(null == cmdLine) {
  +        	this.cmdLine = new String[0];
  +        } else {
  +            Vector v = new Vector();
  +            StringTokenizer st = new StringTokenizer(cmdLine);
  +            while (st.hasMoreTokens()) {
  +                v.addElement(st.nextToken());
  +            }
  +            this.cmdLine = new String[v.size()];
  +            v.copyInto(this.cmdLine);
  +        }
  +    }
  +
  +    public void run() {
  +        boolean failed = true;
  +        try {
  +	    System.out.println("Calling main" );
  +            org.apache.tomcat.startup.Tomcat.main(cmdLine);
  +	    System.out.println("Main returned" );
  +            failed = false;
  +        } catch(Throwable t) {
  +            t.printStackTrace(); // OK
  +        } finally {
  +            if(failed) {
  +		System.out.println("Failed ??");
  +            }
  +        }
  +    }
   }