Bug 1148186

Summary: rhq-agent-wrapper's config and cleanconfig commands source RHQ_AGENT_START_COMMAND instead of executing it resulting in failures
Product: [JBoss] JBoss Operations Network Reporter: Larry O'Leary <loleary>
Component: Agent, Launch ScriptsAssignee: Stefan Negrea <snegrea>
Status: CLOSED CURRENTRELEASE QA Contact: Armine Hovsepyan <ahovsepy>
Severity: medium Docs Contact:
Priority: unspecified    
Version: JON 3.2.3, JON 3.3.0CC: ahovsepy, jshaughn, lcarlon, mazz, mfoley, snegrea, tsegismo
Target Milestone: ER05   
Target Release: JON 3.3.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Users were unable to use the config and cleanconfig commands with the JBoss ON rhq-agent-wrapper if they were using the su or sudo commands in the RHQ_AGENT_START_COMMAND value. JBoss ON encountered errors when attempting to execute these commands with the rhq-agent-wrapper. An environment variable field has been added to the RHQ_AGENT_START_COMMAND value. The RHQ_AGENT_START_COMMAND value can be used with the su or sudo commands to start JBoss ON.
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-12-11 14:00:37 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:
Attachments:
Description Flags
agent_config.log none

Description Larry O'Leary 2014-09-30 21:39:23 UTC
Description of problem:
If you use a command other then a shell script in the value for RHQ_AGENT_START_COMMAND -- such as su or nohup or time -- the config and cleanconfig commands can not be executed from rhq-agent-wrapper.

Version-Release number of selected component (if applicable):
3.2.3

How reproducible:
Always

Steps to Reproduce:
1. Install and configure JBoss ON system.
2. Update rhq-agent-env.sh to and define RHQ_AGENT_START_COMMAND value such as:

   RHQ_AGENT_START_COMMAND="su -m jonadmin -c '${RHQ_AGENT_HOME}/bin/rhq-agent.sh'"

3. Be sure user jonadmin exists.
4. Chown the JBoss ON agent installation and its contents to the jonadmin user.
5. Run rhq-agent-wrapper.sh config

Actual results:
Fails with strange output or error similar to:
    ./rhq-agent-wrapper.sh: line 293: .: /usr/bin/su: cannot execute binary file

Expected results:
Should be prompted for agent configuration and the agent should be successfully configured.

Additional info:
This is due to the config and cleanconfig options in the rhq-agent-wrapper.sh case statement attempting to source the RHQ_AGENT_START_COMMAND value. This is not a valid script command when a binary file or arguments are being used. Even in the case that RHQ_AGENT_START_COMMAND is not explicitly defined, this is probably still not what we want to do. the . or source commands copy the contents of the specified file into the script at the execution point. This is really bad if the contents is binary and still bad if it was an actual executable script as it will result in very bad script nesting and scope issues.

Comment 1 Stefan Negrea 2014-10-08 03:31:02 UTC
Here are the three commits that need to be cherry-picked to the release branch:


commit 1df956d314083e10660c173cbfd562778e4f16b5
Author: Stefan Negrea <snegrea>
Date:   Mon Oct 6 16:36:23 2014 -0500

    [BZ 1148186] One more update to the initial commit:
    
    - Switch to use $_DOLLARZERO variable to correctly identify the location of the script.



commit ca21dac99551fbb62d33db7e66b154857a96a68c
Author: Stefan Negrea <snegrea>
Date:   Mon Oct 6 14:47:39 2014 -0500

    [BZ 1148186] More updates for the initial commit:
    1) Only assign the pwd to RHQ_AGENT_HOME not already defined
    2) Use a temp variable to extract pwd before dirname



commit d583b234429ca466e3e067dc02635394f711a8fd
Author: Stefan Negrea <snegrea>
Date:   Wed Oct 1 17:15:12 2014 -0500

    [BZ 1148186] Use eval to execute the RHQ agent start command. It was incorrectly source

Comment 2 Thomas Segismont 2014-10-09 15:44:36 UTC
Cherry-picked over to release/jon3.3.x



  Branch: refs/heads/release/jon3.3.x
  Home:   https://github.com/rhq-project/rhq
  Commit: c30b551dd4608b92d16f57b6715d14ca64958bc2
      https://github.com/rhq-project/rhq/commit/c30b551dd4608b92d16f57b6715d14ca64958bc2
  Author: Stefan Negrea <snegrea>
  Date:   2014-10-09 (Thu, 09 Oct 2014)

  Changed paths:
    M modules/enterprise/agent/src/etc/rhq-agent-wrapper.sh

  Log Message:
  -----------
  [BZ 1148186] Use eval to execute the RHQ agent start command. It was incorrectly sourced in the current script. Note that only config and full config were affected. Also, adjusted the order for defining and export RHQ home to allow proper overrides int RHQ environment script.

(cherry picked from commit d583b234429ca466e3e067dc02635394f711a8fd)
Signed-off-by: Thomas Segismont <tsegismo>


  Commit: e214e93387a7f815ecef66260dbd4220d489f9b6
      https://github.com/rhq-project/rhq/commit/e214e93387a7f815ecef66260dbd4220d489f9b6
  Author: Stefan Negrea <snegrea>
  Date:   2014-10-09 (Thu, 09 Oct 2014)

  Changed paths:
    M modules/enterprise/agent/src/etc/rhq-agent-wrapper.sh

  Log Message:
  -----------
  [BZ 1148186] More updates for the initial commit:
1) Only assign the pwd to RHQ_AGENT_HOME not already defined
2) Use a temp variable to extract pwd before dirname

(cherry picked from commit ca21dac99551fbb62d33db7e66b154857a96a68c)
Signed-off-by: Thomas Segismont <tsegismo>


  Commit: 806230cd33d43817509f72fddcc8fe97703faed9
      https://github.com/rhq-project/rhq/commit/806230cd33d43817509f72fddcc8fe97703faed9
  Author: Stefan Negrea <snegrea>
  Date:   2014-10-09 (Thu, 09 Oct 2014)

  Changed paths:
    M modules/enterprise/agent/src/etc/rhq-agent-wrapper.sh

  Log Message:
  -----------
  [BZ 1148186] One more update to the initial commit:

- Switch to use $_DOLLARZERO variable to correctly identify the location of the script.

(cherry picked from commit 1df956d314083e10660c173cbfd562778e4f16b5)
Signed-off-by: Thomas Segismont <tsegismo>


Compare: https://github.com/rhq-project/rhq/compare/3a5701178868...806230cd33d4

Comment 4 John Mazzitelli 2014-10-15 21:46:37 UTC
FYI: this fix broke the dev-container build on Mac - see bug #1153373

Comment 5 Stefan Negrea 2014-10-21 14:59:06 UTC
bug 1153373 does not impact JON since OSX is not a supported platform. A fix has already been deployed for the RHQ community release but will not be backported to JON 3.3.

Comment 6 Simeon Pinder 2014-10-21 20:24:41 UTC
Moving to ON_QA as available to test with the latest brew build:
https://brewweb.devel.redhat.com//buildinfo?buildID=394734

Comment 7 Armine Hovsepyan 2014-10-24 12:43:28 UTC
Created attachment 950382 [details]
agent_config.log

Comment 8 Armine Hovsepyan 2014-10-24 12:43:57 UTC
verified in JON 3.3 ER05
log attached