Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1148186] Use eval to execute the RHQ agent start command. It was …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Stefan Negrea committed Oct 1, 2014
1 parent 10795bd commit d583b23
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions modules/enterprise/agent/src/etc/rhq-agent-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,20 @@ else
_DOLLARZERO=`readlink $_READLINK_ARG "$0" 2>/dev/null || echo "$0"`
fi

RHQ_AGENT_WRAPPER_BIN_DIR_PATH=`dirname "$_DOLLARZERO"`
debug_wrapper_msg "RHQ_AGENT_WRAPPER_BIN_DIR_PATH=$RHQ_AGENT_WRAPPER_BIN_DIR_PATH"

# Define and export RHQ_AGENT_HOME, we will assume we are running
# directly from the agent installation's bin directory
# Note: later sourced scripts can and may override this
RHQ_AGENT_HOME=`dirname $PWD`
export $RHQ_AGENT_HOME


# -------------------------------
# Read in the rhq-agent-env.sh file so we get the configured agent environment

RHQ_AGENT_WRAPPER_BIN_DIR_PATH=`dirname "$_DOLLARZERO"`
debug_wrapper_msg "RHQ_AGENT_WRAPPER_BIN_DIR_PATH=$RHQ_AGENT_WRAPPER_BIN_DIR_PATH"

if [ -f "${RHQ_AGENT_WRAPPER_BIN_DIR_PATH}/rhq-agent-env.sh" ]; then
debug_wrapper_msg "Loading environment script: ${RHQ_AGENT_WRAPPER_BIN_DIR_PATH}/rhq-agent-env.sh"
. "${RHQ_AGENT_WRAPPER_BIN_DIR_PATH}/rhq-agent-env.sh" $*
Expand Down Expand Up @@ -197,18 +205,11 @@ _THIS_SCRIPT="${_THIS_SCRIPT_DIR}"/`basename "$_DOLLARZERO"`

# -------------------------------
# Figure out where the RHQ Agent's home directory is and cd to it.
# If RHQ_AGENT_HOME is not defined, we will assume we are running
# directly from the agent installation's bin directory
cd "${RHQ_AGENT_HOME}" || {
echo "Cannot go to the RHQ_AGENT_HOME directory: ${RHQ_AGENT_HOME}"
exit 1
}

if [ -z "$RHQ_AGENT_HOME" ]; then
cd ..
RHQ_AGENT_HOME=`pwd`
else
cd "${RHQ_AGENT_HOME}" || {
echo "Cannot go to the RHQ_AGENT_HOME directory: ${RHQ_AGENT_HOME}"
exit 1
}
fi

# -------------------------------
# create the logs directory
Expand Down Expand Up @@ -337,7 +338,7 @@ case "$1" in
debug_wrapper_msg "Executing agent with command: ${RHQ_AGENT_START_COMMAND} ${RHQ_AGENT_CMDLINE_OPTS}"
fi

. $RHQ_AGENT_START_COMMAND
eval "$RHQ_AGENT_START_COMMAND"

;;

Expand Down Expand Up @@ -375,7 +376,7 @@ case "$1" in
debug_wrapper_msg "Executing agent with command: ${RHQ_AGENT_START_COMMAND} ${RHQ_AGENT_CMDLINE_OPTS}"
fi

. $RHQ_AGENT_START_COMMAND
eval "$RHQ_AGENT_START_COMMAND"

;;

Expand Down

2 comments on commit d583b23

@tsegismont
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't change this logic but why do we "assume" we are running directly from the agent installation's bin directory? In other words, why:

RHQ_AGENT_HOME=`dirname $PWD`

instead of:

RHQ_AGENT_HOME=`dirname "$_DOLLARZERO"`

@loleary
Copy link
Contributor

@loleary loleary commented on d583b23 Oct 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$PWD isn't always defined either. It is best to use pwd. Also, in its current state it will break long file names.

It also seems that we are doing the wrong thing here. First, we are ignoring the user's defined RHQ_AGENT_HOME. Second, we are assuming RHQ_AGENT_HOME is the current work directory. This is most likely not the case. Why did this change?

Please sign in to comment.