Bug 768707

Summary: Passing agent command-line options via start script/environment prevents agent from starting as normal
Product: [Other] RHQ Project Reporter: Larry O'Leary <loleary>
Component: AgentAssignee: Charles Crouch <ccrouch>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.2CC: ccrouch, hbrock, hrupp, mazz
Target Milestone: ---   
Target Release: JON 3.1.0, RHQ 4.3.0   
Hardware: All   
OS: All   
See Also: https://bugzilla.redhat.com/show_bug.cgi?id=768706
Fixed In Version: 4.3 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-08-31 06:09:47 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Bug Depends On:    
Bug Blocks: 782579    

Description Larry O'Leary 2011-12-18 01:23:21 EST
Description of problem:
When setting RHQ_AGENT_CMDLINE_OPTS, the agent no longer starts as expected. This is due to the RHQ_AGENT_CMDLINE_OPTS being used directly in the rhq-agent.sh, rhq-agent-wrapper.sh, rhq-agent.bat, and rhq-agent-wrapper.bat scripts. Essentially, the start scripts check to see if the variable is set and if it is, the default options are not added to the variable. This includes the processing of additional command-line arguments.

Instead, the start scripts should probably use an RHQ_AGENT_ADDITIONAL_CMDLINE_OPTS similar to the RHQ_AGENT_ADDITIONAL_JAVA_OPTS environment variables. This will allow the defaults to continue to be used, along with arguments passed on the command-line itself and the additional options (such as the --pref=mynodename or --nonative) to be added to the start commands in addition to RHQ_AGENT_CMDLINE_OPTS and the options passed on the command-line directly.

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

How reproducible:

Steps to Reproduce:
1. Edit rhq-agent-env.sh to set --pref=mynode in the RHQ_AGENT_CMDLINE_OPTS
2. Attempt to start the agent with rhq-agent.sh --cleanconfig
Actual results:
Agent starts using its current configuration and does not prompt for new configuration.

Expected results:
Agent should have prompted for new configuration.

Additional info:
Although the rhq-agent-env.[sh|bat] script indicates that $@ or %* can be added to have the command-line arguments also passed in, this does not fix all situations. For example, on Linux/UNIX the --daemon argument is expected when starting the agent using the rhq-agent-wrapper.sh script. However, if you add the --daemon argument to the RHQ_AGENT_CMDLINE_OPTS the result is the rhq-agent.sh script no longer works as expected. Instead, you must continue to edit the rhq-agent-env.sh script depending on which start option you want to use.
Comment 1 Ian Springer 2012-02-03 11:56:52 EST
I think the issue here is the following lines in rhq-agent-wrapper.sh and the equivalent lines in rhq-agent-wrapper.bat:

if [ "x$RHQ_AGENT_CMDLINE_OPTS" = "x" ]; then

These lines run after rhq-agent-env.sh is sourced.

They should be replaced with something like:

for opt in $RHQ_AGENT_CMDLINE_OPTS; do
   if [ "$opt" = "-d" ] || [ "$opt" = "--daemon" ]; then
if [ "$found_daemon_option" = "0" ]; then

This way, we ensure the --daemon option always gets included in $RHQ_AGENT_CMDLINE_OPTS, whether or not the user defined RHQ_AGENT_CMDLINE_OPTS. Because the wrapper scripts always want the daemon option.

I don't think we need to add support for a RHQ_AGENT_ADDITIONAL_CMDLINE_OPTS variable, since the wrapper script setting of --daemon is the one special case of a hard-coded option. The scripts don't set any default options that are only used when RHQ_AGENT_CMDLINE_OPTS is not predefined, so it's a bit of a different beast than RHQ_AGENT_JAVA_OPTS.

Note, due to the fact that rhq-agent-env.sh is used by both rhq-agent-wrapper.sh and rhq-agent.sh, users should never include --daemon when setting RHQ_AGENT_CMDLINE_OPTS in rhq-agent-env.sh. We should remove it from the commented out "#RHQ_AGENT_CMDLINE_OPTS=" line in the default rhq-agent-env.sh and add a comment telling users to never include --daemon in the value. I'll create a separate BZ for that change.
Comment 2 John Mazzitelli 2012-02-03 12:04:13 EST
ian's proposed fix to rhq-agent-wrapper.sh looks good. I would recommend that solution. Yes, the point was to always make sure --daemon should be there (even though what we have didn't really do that 100% of the time). However we can ensure that --daemon is there, we should do it.
Comment 3 Mike Foley 2012-02-06 12:02:31 EST
per bz triage (asantos, ccrouch, mfoley. loleary)
Comment 4 Ian Springer 2012-02-15 14:41:55 EST
Fixed in master:


Note, the fix was not required on the Windows side, because rhq-agent-wrapper.bat does not use the RHQ_AGENT_CMDLINE_OPTS variable. Instead, when starting the Agent via rhq-agent-wrapper.bat, Agent command line options must be specified in wrapper\rhq-agent-wrapper.conf or wrapper\rhq-agent-wrapper.inc. I did add some better comments in rhq-agent-env.bat regarding RHQ_AGENT_CMDLINE_OPTS and a couple other variables not being used by rhq-agent-wrapper.bat.
Comment 6 Heiko W. Rupp 2013-08-31 06:09:47 EDT
Bulk close of old bugs in VERIFIED state.