Red Hat Bugzilla – Bug 768707
Passing agent command-line options via start script/environment prevents agent from starting as normal
Last modified: 2015-02-01 18:27:16 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):
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
Agent starts using its current configuration and does not prompt for new configuration.
Agent should have prompted for new configuration.
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.
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.
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.
per bz triage (asantos, ccrouch, mfoley. loleary)
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.
Bulk close of old bugs in VERIFIED state.