Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 961437

Summary: [as7] Start operation returns failure when start script returns exit code 0 (success)
Product: [JBoss] JBoss Operations Network Reporter: Larry O'Leary <loleary>
Component: Operations, Plugin -- JBoss EAP 6Assignee: Larry O'Leary <loleary>
Status: CLOSED NEXTRELEASE QA Contact: Mike Foley <mfoley>
Severity: high Docs Contact:
Priority: urgent    
Version: JON 3.1.1CC: jkremser
Target Milestone: ER01   
Target Release: JON 3.1.3   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 894493
: 961438 (view as bug list) Environment:
Last Closed: 2013-09-06 02:24:49 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 894493    
Bug Blocks: 961438    

Description Larry O'Leary 2013-05-09 15:26:15 UTC
Back-port to the 3.1.x branch.

+++ This bug was initially created as a clone of JBoss ON 3.2 Bug #894493 +++

Description of problem:
After invoking the start operation on an AS7/EAP6 resource, the operation status is reported as failure even thought the resource is started and the script output indicates that the resource was started successfully and exited cleanly with return code 0.

The only time the start operation reports success is when the start script blocks (i.e. does not return).

Version-Release number of selected component (if applicable):
4.4.0.JON311GA

How reproducible:
Always

Steps to Reproduce:
1.  Install and configure EAP 6 standalone server
2.  Create custom standalone.sh start script wrapper which returns an exit code:

cat > "${JBOSS_HOME}/bin/standalone-wrapper.sh" << EOF
#!/bin/sh

DIRNAME=\$(dirname "\$0")

eval \"\${DIRNAME}/standalone.sh\" "\$@" \&
exit \$?
EOF
chmod +x "${JBOSS_HOME}/bin/standalone-wrapper.sh"

3.  Using the newly created start script wrapper, start the EAP 6 standalone server
4.  Start JBoss ON system
5.  Import EAP 6 standalone server into inventory
6.  Configure the EAP 6 resource's connection settings to use the custom start script wrapper standalone-wrapper.sh
7.  After EAP 6 resource shows availability of UP, invoke its shutdown operation
8.  Wait until EAP 6 resource is reported as DOWN
9.  Invoke the EAP 6 resource's start operation

Actual results:
EAP server is started but operation status in UI shows Failure with the following error message available from the UI:

    java.lang.Exception: Start failed with error code 0:

	    at org.rhq.core.pc.operation.OperationInvocation.run(OperationInvocation.java:278)
	    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	    at java.lang.Thread.run(Thread.java:636)

Expected results:
EAP server is started and the operation status in the UI shows Success.

Additional info:
This is a direct result of incorrectly handling the process exit code from .ProcessExecutionResults.getExitCode() in BaseServerComponent.startServer(). We treat <null> as success when really 0 is success and <null> simply means that the request has not yet returned or is blocking or timed out.

To fix this:

diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/Ba
index 98a46d2..3dc12de 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
@@ -330,7 +330,7 @@ public abstract class BaseServerComponent<T extends ResourceComponent<?>> extend
         logExecutionResults(results);
         if (results.getError() != null) {
             operationResult.setErrorMessage(results.getError().getMessage());
-        } else if (results.getExitCode() != null) {
+        } else if (results.getExitCode() != null && results.getExitCode() != 0) {
             operationResult.setErrorMessage("Start failed with error code " + results.getExitCode() + ":\n" + results.getCapturedOutput());
         } else {
             // Try to connect to the server - ping once per second, timing out after 20s.

--- Additional comment from Jirka Kremser on 2013-02-04 05:52:10 EST ---

I did something similar for as6 (feb01f468)

--- Additional comment from Jirka Kremser on 2013-03-06 06:41:08 EST ---

master
http://git.fedorahosted.org/cgit/rhq/rhq.git/commit/?id=c0fe931b7

time:    Wed Mar 6 12:24:27 2013 +0100
commit:  c0fe931b74ac8eccfc5be8af2275bea5d8c0c917
author:  Jirka Kremser - jkremser
message: [BZ 894493] - [as7] Start operation returns failure when start script returns exit code 0 (success). Added the test for the exit code.

Comment 1 Larry O'Leary 2013-05-09 23:33:59 UTC
Committed to release/jon3.1.x as https://git.fedorahosted.org/cgit/rhq/rhq.git/commit/?id=ca4fdfafa7546c03d6d809d2c01a50f8cedc4432:

commit ca4fdfafa7546c03d6d809d2c01a50f8cedc4432
Author: Jirka Kremser <jkremser>
Date:   Wed Mar 6 12:24:27 2013 +0100

    [BZ 894493] - [as7] Start operation returns failure when start script returns exit code 0 (success). Added the test for the exit code.
    (cherry-pick from c0fe931b74ac8eccfc5be8af2275bea5d8c0c917)

Comment 2 Larry O'Leary 2013-09-06 02:24:49 UTC
Closing as there will not be a 3.1.3 release. This is being tracked for 3.2 in the 'depends on' field.