[jopr-commits] JOPR SVN: r1138 - trunk/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat.

jopr-commits at lists.jboss.org jopr-commits at lists.jboss.org
Tue Sep 1 18:59:07 EDT 2009


Author: ips
Date: 2009-09-01 18:59:07 -0400 (Tue, 01 Sep 2009)
New Revision: 1138

Modified:
   trunk/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
Log:
for Start operation, if using script method on Windows (i.e. startup.bat), don't consider an exit code of 1 to be an error (fix for items 7 and 9 from  https://jira.jboss.org/jira/browse/JOPR-354)



Modified: trunk/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java
===================================================================
--- trunk/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java	2009-09-01 21:08:25 UTC (rev 1137)
+++ trunk/modules/plugins/tomcat/src/main/java/org/jboss/on/plugins/tomcat/TomcatServerOperationsDelegate.java	2009-09-01 22:59:07 UTC (rev 1138)
@@ -159,9 +159,10 @@
      */
     private String start(PropertyList environment) throws InterruptedException {
         Configuration pluginConfiguration = this.serverComponent.getPluginConfiguration();
-        String controlMethod = pluginConfiguration.getSimpleValue(TomcatServerComponent.PLUGIN_CONFIG_CONTROL_METHOD,
+        String controlMethodName = pluginConfiguration.getSimpleValue(TomcatServerComponent.PLUGIN_CONFIG_CONTROL_METHOD,
             ControlMethod.SCRIPT.name());
-        ProcessExecution processExecution = (ControlMethod.SCRIPT.name().equals(controlMethod)) ? getScriptStart(pluginConfiguration)
+        ControlMethod controlMethod = ControlMethod.valueOf(controlMethodName);
+        ProcessExecution processExecution = (controlMethod == ControlMethod.SCRIPT) ? getScriptStart(pluginConfiguration)
             : getRpmStart(pluginConfiguration);
 
         applyEnvironmentVars(environment, processExecution);
@@ -176,16 +177,16 @@
         Integer exitCode = results.getExitCode();
         AvailabilityType avail;
 
-        if ((null != error) || ((null != exitCode) && (0 != exitCode))) {
-            String message = "Script returned error or non-zero exit code while starting the Tomcat instance. Exit code ["
-                + exitCode + "]";
-            if (null == error) {
+        if (startScriptFailed(controlMethod, error, exitCode)) {
+            String output = results.getCapturedOutput();
+            String message = "Script returned error or non-zero exit code while starting the Tomcat instance - exitCode=["
+                + ((exitCode != null) ? exitCode : "UNKNOWN") + "], output=[" + output + "].";
+            if (error == null) {
                 log.error(message);
             } else {
                 log.error(message, error);
             }
             avail = this.serverComponent.getAvailability();
-
         } else {
             avail = waitForServerToStart(start);
         }
@@ -196,7 +197,18 @@
         } else {
             return "Server has been started.";
         }
+    }
 
+    private static boolean startScriptFailed(ControlMethod controlMethod, Throwable error, Integer exitCode) {
+        if (error != null || exitCode == null) {
+            return true;
+        }
+        if (controlMethod == ControlMethod.SCRIPT && isWindows()) {
+            // Believe it or not, an exit code of 1 from startup.bat does not indicate an error.
+            return exitCode != 0 && exitCode != 1;
+        } else {
+            return exitCode != 0;
+        }
     }
 
     private ProcessExecution getScriptStart(Configuration pluginConfiguration) {
@@ -282,7 +294,7 @@
         String controlMethod = pluginConfiguration.getSimpleValue(TomcatServerComponent.PLUGIN_CONFIG_CONTROL_METHOD,
             ControlMethod.SCRIPT.name());
         ProcessExecution processExecution = (ControlMethod.SCRIPT.name().equals(controlMethod)) ? getScriptShutdown(pluginConfiguration)
-            : getRpmShutdown(pluginConfiguration);
+            : getRpmShutdown();
         
         applyEnvironmentVars(environment, processExecution);
         
@@ -319,7 +331,7 @@
         return processExecution;
     }
 
-    private ProcessExecution getRpmShutdown(Configuration pluginConfiguration) {
+    private ProcessExecution getRpmShutdown() {
         ProcessExecution processExecution;
         String catalinaHome = this.serverComponent.getCatalinaHome().getPath();
         String rpm = TomcatDiscoveryComponent.isEWSTomcat6(catalinaHome) ? TomcatDiscoveryComponent.EWS_TOMCAT_6
@@ -496,4 +508,8 @@
             processExecution.setEnvironmentVariables(environmentVariables);
         }
     }
+
+    private static boolean isWindows() {
+        return File.separatorChar == '\\';
+    }
 }
\ No newline at end of file



More information about the jopr-commits mailing list