Bug 768707 - Passing agent command-line options via start script/environment prevents agent from starting as normal
Summary: Passing agent command-line options via start script/environment prevents agen...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: RHQ Project
Classification: Other
Component: Agent
Version: 4.2
Hardware: All
OS: All
medium
medium
Target Milestone: ---
: JON 3.1.0,RHQ 4.3.0
Assignee: Charles Crouch
QA Contact: Mike Foley
URL:
Whiteboard:
Depends On:
Blocks: jon310-sprint11, rhq44-sprint11
TreeView+ depends on / blocked
 
Reported: 2011-12-18 06:23 UTC by Larry O'Leary
Modified: 2018-11-26 18:06 UTC (History)
4 users (show)

Fixed In Version: 4.3
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-08-31 10:09:47 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 768706 0 high CLOSED Agent needs to use a unique Java Preference node name 2021-02-22 00:41:40 UTC
Red Hat Bugzilla 787250 0 unspecified CLOSED [rhq-agent-env.sh/bat] --daemon should not be in example value for RHQ_AGENT_CMDLINE_OPTS and comment should be added sa... 2021-02-22 00:41:40 UTC

Internal Links: 768706 787250

Description Larry O'Leary 2011-12-18 06:23:21 UTC
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:
Always

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 16:56:52 UTC
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
   RHQ_AGENT_CMDLINE_OPTS=--daemon
fi
export RHQ_AGENT_CMDLINE_OPTS

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

They should be replaced with something like:

found_daemon_option=0
for opt in $RHQ_AGENT_CMDLINE_OPTS; do
   if [ "$opt" = "-d" ] || [ "$opt" = "--daemon" ]; then
      found_daemon_option=1
      break
   fi
done
if [ "$found_daemon_option" = "0" ]; then
   RHQ_AGENT_CMDLINE_OPTS="--daemon $RHQ_AGENT_CMDLINE_OPTS"
fi
export RHQ_AGENT_CMDLINE_OPTS

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 17:04:13 UTC
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 17:02:31 UTC
per bz triage (asantos, ccrouch, mfoley. loleary)

Comment 4 Ian Springer 2012-02-15 19:41:55 UTC
Fixed in master:

http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=commitdiff;h=31181a3
and:
http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=commitdiff;h=d838043

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 10:09:47 UTC
Bulk close of old bugs in VERIFIED state.


Note You need to log in before you can comment on or make changes to this bug.