Author: funkman
Date: Thu Nov  4 15:47:56 2010
New Revision: 1031043

URL: http://svn.apache.org/viewvc?rev=1031043&view=rev
Log:
Allow for configest

Now one may type in bin/configtest.sh and then check the 
exit code.

This will try to use the default loggers so it may spew 
"a lot" to stdout/err so as to avoid clobbering existing
log files in use.

Potential future todo 
- Making the parsing of server.xml more finicky as to avoid
  bad values being ignored (example - use 'x8005' as the
  shutdown port - and tomcat still starts up fine )



Added:
    tomcat/trunk/bin/configtest.sh   (with props)
Modified:
    tomcat/trunk/bin/catalina.sh
    tomcat/trunk/build.xml
    tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java
    tomcat/trunk/java/org/apache/catalina/startup/Catalina.java

Modified: tomcat/trunk/bin/catalina.sh
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/bin/catalina.sh?rev=1031043&r1=1031042&r2=1031043&view=diff
==============================================================================
--- tomcat/trunk/bin/catalina.sh (original)
+++ tomcat/trunk/bin/catalina.sh Thu Nov  4 15:47:56 2010
@@ -474,6 +474,16 @@ elif [ "$1" = "stop" ] ; then
     fi
   fi
 
+elif [ "$1" = "configtest" ] ; then
+
+    eval \"$_RUNJAVA\" $JAVA_OPTS $CATALINA_OPTS \
+      -Djava.endorsed.dirs=\"$JAVA_ENDORSED_DIRS\" -classpath \"$CLASSPATH\" \
+      -Dcatalina.base=\"$CATALINA_BASE\" \
+      -Dcatalina.home=\"$CATALINA_HOME\" \
+      -Djava.io.tmpdir=\"$CATALINA_TMPDIR\" \
+      org.apache.catalina.startup.Bootstrap configtest 
+    exit $?
+
 elif [ "$1" = "version" ] ; then
 
     "$_RUNJAVA"   \

Added: tomcat/trunk/bin/configtest.sh
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/bin/configtest.sh?rev=1031043&view=auto
==============================================================================
--- tomcat/trunk/bin/configtest.sh (added)
+++ tomcat/trunk/bin/configtest.sh Thu Nov  4 15:47:56 2010
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# -----------------------------------------------------------------------------
+# configtest for the CATALINA Server
+#
+# $Id: configtest.sh  $
+# -----------------------------------------------------------------------------
+
+# Better OS/400 detection: see Bugzilla 31132
+os400=false
+darwin=false
+case "`uname`" in
+CYGWIN*) cygwin=true;;
+OS400*) os400=true;;
+Darwin*) darwin=true;;
+esac
+
+# resolve links - $0 may be a softlink
+PRG="$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
+ 
+PRGDIR=`dirname "$PRG"`
+EXECUTABLE=catalina.sh
+
+# Check that target executable exists
+if $os400; then
+  # -x will Only work on the os400 if the files are: 
+  # 1. owned by the user
+  # 2. owned by the PRIMARY group of the user
+  # this will not work if the user belongs in secondary groups
+  eval
+else
+  if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
+    echo "Cannot find $PRGDIR/$EXECUTABLE"
+    echo "This file is needed to run this program"
+    exit 1
+  fi
+fi 
+
+exec "$PRGDIR"/"$EXECUTABLE" configtest "$@"
+

Propchange: tomcat/trunk/bin/configtest.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/bin/configtest.sh
------------------------------------------------------------------------------
    svn:executable = *

Modified: tomcat/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=1031043&r1=1031042&r2=1031043&view=diff
==============================================================================
--- tomcat/trunk/build.xml (original)
+++ tomcat/trunk/build.xml Thu Nov  4 15:47:56 2010
@@ -1763,6 +1763,7 @@ Apache Tomcat ${version} native binaries
          tarfile="${tomcat.release}/v${version}/bin/${final.name}.tar.gz">
       <tarfileset dir="${tomcat.dist}" mode="755" prefix="${final.name}">
         <include name="bin/catalina.sh" />
+        <include name="bin/configtest.sh" />
         <include name="bin/digest.sh" />
         <include name="bin/jasper.sh" />
         <include name="bin/jspc.sh" />
@@ -1792,6 +1793,7 @@ Apache Tomcat ${version} native binaries
         <include name="RUNNING.txt" />
         <include name="BENCHMARKS.txt" />
         <exclude name="bin/catalina.sh" />
+        <exclude name="bin/configtest.sh" />
         <exclude name="bin/digest.sh" />
         <exclude name="bin/jasper.sh" />
         <exclude name="bin/jspc.sh" />

Modified: tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java?rev=1031043&r1=1031042&r2=1031043&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java Thu Nov  4 
15:47:56 2010
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -54,7 +54,7 @@ import org.apache.juli.logging.LogFactor
 public final class Bootstrap {
 
     private static final Log log = LogFactory.getLog(Bootstrap.class);
-    
+
     // -------------------------------------------------------------- Constants
 
 
@@ -115,7 +115,7 @@ public final class Bootstrap {
         ArrayList<String> repositoryLocations = new ArrayList<String>();
         ArrayList<Integer> repositoryTypes = new ArrayList<Integer>();
         int i;
- 
+
         StringTokenizer tokenizer = new StringTokenizer(value, ",");
         while (tokenizer.hasMoreElements()) {
             String repository = tokenizer.nextToken();
@@ -126,20 +126,20 @@ public final class Bootstrap {
             while ((i=repository.indexOf(CATALINA_HOME_TOKEN))>=0) {
                 replace=true;
                 if (i>0) {
-                repository = repository.substring(0,i) + getCatalinaHome() 
+                repository = repository.substring(0,i) + getCatalinaHome()
                     + repository.substring(i+CATALINA_HOME_TOKEN.length());
                 } else {
-                    repository = getCatalinaHome() 
+                    repository = getCatalinaHome()
                         + repository.substring(CATALINA_HOME_TOKEN.length());
                 }
             }
             while ((i=repository.indexOf(CATALINA_BASE_TOKEN))>=0) {
                 replace=true;
                 if (i>0) {
-                repository = repository.substring(0,i) + getCatalinaBase() 
+                repository = repository.substring(0,i) + getCatalinaBase()
                     + repository.substring(i+CATALINA_BASE_TOKEN.length());
                 } else {
-                    repository = getCatalinaBase() 
+                    repository = getCatalinaBase()
                         + repository.substring(CATALINA_BASE_TOKEN.length());
                 }
             }
@@ -172,7 +172,7 @@ public final class Bootstrap {
 
         String[] locations = repositoryLocations.toArray(new String[0]);
         Integer[] types = repositoryTypes.toArray(new Integer[0]);
- 
+
         ClassLoader classLoader = ClassLoaderFactory.createClassLoader
             (locations, types, parent);
 
@@ -255,7 +255,7 @@ public final class Bootstrap {
             param = new Object[1];
             param[0] = arguments;
         }
-        Method method = 
+        Method method =
             catalinaDaemon.getClass().getMethod(methodName, paramTypes);
         if (log.isDebugEnabled())
             log.debug("Calling startup class " + method);
@@ -264,6 +264,19 @@ public final class Bootstrap {
     }
 
 
+    /**
+     * getServer() for configtest
+     */
+    private Object getServer() throws Exception {
+
+        String methodName = "getServer";
+        Method method =
+            catalinaDaemon.getClass().getMethod(methodName);
+        return method.invoke(catalinaDaemon);
+
+    }
+
+
     // ----------------------------------------------------------- Main Program
 
 
@@ -310,7 +323,7 @@ public final class Bootstrap {
     public void stopServer()
         throws Exception {
 
-        Method method = 
+        Method method =
             catalinaDaemon.getClass().getMethod("stopServer", (Class []) null);
         method.invoke(catalinaDaemon, (Object []) null);
 
@@ -334,7 +347,7 @@ public final class Bootstrap {
             param = new Object[1];
             param[0] = arguments;
         }
-        Method method = 
+        Method method =
             catalinaDaemon.getClass().getMethod("stopServer", paramTypes);
         method.invoke(catalinaDaemon, param);
 
@@ -351,7 +364,7 @@ public final class Bootstrap {
         paramTypes[0] = Boolean.TYPE;
         Object paramValues[] = new Object[1];
         paramValues[0] = Boolean.valueOf(await);
-        Method method = 
+        Method method =
             catalinaDaemon.getClass().getMethod("setAwait", paramTypes);
         method.invoke(catalinaDaemon, paramValues);
 
@@ -418,12 +431,19 @@ public final class Bootstrap {
                 daemon.start();
             } else if (command.equals("stop")) {
                 daemon.stopServer(args);
+            } else if (command.equals("configtest")) {
+                daemon.load(args);
+                if (null==daemon.getServer()) {
+                    System.exit(1);
+                }
+                System.exit(0);
             } else {
                 log.warn("Bootstrap: command \"" + command + "\" does not 
exist.");
             }
         } catch (Throwable t) {
             handleThrowable(t);
             t.printStackTrace();
+            System.exit(1);
         }
 
     }
@@ -463,12 +483,12 @@ public final class Bootstrap {
 
         if (System.getProperty(Globals.CATALINA_HOME_PROP) != null)
             return;
-        File bootstrapJar = 
+        File bootstrapJar =
             new File(System.getProperty("user.dir"), "bootstrap.jar");
         if (bootstrapJar.exists()) {
             try {
                 System.setProperty
-                    (Globals.CATALINA_HOME_PROP, 
+                    (Globals.CATALINA_HOME_PROP,
                      (new File(System.getProperty("user.dir"), ".."))
                      .getCanonicalPath());
             } catch (Exception e) {

Modified: tomcat/trunk/java/org/apache/catalina/startup/Catalina.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Catalina.java?rev=1031043&r1=1031042&r2=1031043&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Catalina.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Catalina.java Thu Nov  4 
15:47:56 2010
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -57,6 +57,7 @@ import org.xml.sax.InputSource;
  *     "catalina.base" system property.   [conf/server.xml]
  * <li><b>-help</b>      - Display usage information.
  * <li><b>-nonaming</b>  - Disable naming support.
+ * <li><b>configtest</b> - Try to test the config
  * <li><b>start</b>      - Start an instance of Catalina.
  * <li><b>stop</b>       - Stop the currently running instance of Catalina.
  * </u>
@@ -103,7 +104,7 @@ public class Catalina {
      */
     protected Server server = null;
 
-    
+
     /**
      * Are we starting a new server?
      */
@@ -135,12 +136,12 @@ public class Catalina {
 
 
     // ----------------------------------------------------------- Constructors
-    
+
     public Catalina() {
         setSecurityProtection();
     }
-    
-    
+
+
     // ------------------------------------------------------------- Properties
 
 
@@ -250,6 +251,9 @@ public class Catalina {
             } else if (args[i].equals("start")) {
                 starting = true;
                 stopping = false;
+            } else if (args[i].equals("configtest")) {
+                starting = true;
+                stopping = false;
             } else if (args[i].equals("stop")) {
                 starting = false;
                 stopping = true;
@@ -344,10 +348,10 @@ public class Catalina {
                             "addExecutor",
                             "org.apache.catalina.Executor");
 
-        
+
         digester.addRule("Server/Service/Connector",
                          new ConnectorCreateRule());
-        digester.addRule("Server/Service/Connector", 
+        digester.addRule("Server/Service/Connector",
                          new SetAllPropertiesRule(new String[]{"executor"}));
         digester.addSetNext("Server/Service/Connector",
                             "addConnector",
@@ -440,7 +444,7 @@ public class Catalina {
 
         // Stop the existing server
         try {
-            if (getServer().getPort()>0) { 
+            if (getServer().getPort()>0) {
                 Socket socket = new Socket(getServer().getAddress(),
                         getServer().getPort());
                 OutputStream stream = socket.getOutputStream();
@@ -513,7 +517,7 @@ public class Catalina {
                 // Ignore
             }
         }
-        
+
 
         if ((inputStream == null) && (file != null)) {
             log.warn("Can't load server.xml from " + file.getAbsolutePath());
@@ -545,9 +549,9 @@ public class Catalina {
         } catch (LifecycleException e) {
             if 
(Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"))
                 throw new java.lang.Error(e);
-            else   
+            else
                 log.error("Catalina.start", e);
-            
+
         }
 
         long t2 = System.nanoTime();
@@ -557,7 +561,7 @@ public class Catalina {
     }
 
 
-    /* 
+    /*
      * Load using arguments
      */
     public void load(String args[]) {
@@ -605,7 +609,7 @@ public class Catalina {
                     shutdownHook = new CatalinaShutdownHook();
                 }
                 Runtime.getRuntime().addShutdownHook(shutdownHook);
-                
+
                 // If JULI is being used, disable JULI's shutdown hook since
                 // shutdown hooks run in parallel and log messages may be lost
                 // if JULI's hook completes before the CatalinaShutdownHook()
@@ -635,7 +639,7 @@ public class Catalina {
     public void stop() {
 
         try {
-            // Remove the ShutdownHook first so that server.stop() 
+            // Remove the ShutdownHook first so that server.stop()
             // doesn't get invoked twice
             if (useShutdownHook) {
                 Runtime.getRuntime().removeShutdownHook(shutdownHook);
@@ -708,7 +712,7 @@ public class Catalina {
                 }
             }
         }
-        // last resort - for minimal/embedded cases. 
+        // last resort - for minimal/embedded cases.
         if(catalinaHome==null) {
             catalinaHome=System.getProperty("user.dir");
         }
@@ -739,7 +743,7 @@ public class Catalina {
             }
             System.setProperty(Globals.CATALINA_BASE_PROP, catalinaBase);
         }
-        
+
         String temp = System.getProperty("java.io.tmpdir");
         if (temp == null || (!(new File(temp)).exists())
                 || (!(new File(temp)).isDirectory())) {
@@ -748,7 +752,7 @@ public class Catalina {
 
     }
 
-    
+
     protected void initStreams() {
         // Replace System.out and System.err with a custom PrintStream
         SystemLogHandler systemlog = new SystemLogHandler(System.out);
@@ -756,7 +760,7 @@ public class Catalina {
         System.setErr(systemlog);
     }
 
-    
+
     protected void initNaming() {
         // Setting additional variables
         if (!useNaming) {
@@ -785,7 +789,7 @@ public class Catalina {
         }
     }
 
-    
+
     /**
      * Set the security package access/protection.
      */
@@ -794,8 +798,8 @@ public class Catalina {
         securityConfig.setPackageDefinition();
         securityConfig.setPackageAccess();
     }
-    
-    
+
+
     // --------------------------------------- CatalinaShutdownHook Inner Class
 
     // XXX Should be moved to embedded !
@@ -823,8 +827,8 @@ public class Catalina {
             }
         }
     }
-    
-    
+
+
     private static final org.apache.juli.logging.Log log=
         org.apache.juli.logging.LogFactory.getLog( Catalina.class );
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to