Bug 1042495 - CLI changes working directory; making it harder to run scripts
Summary: CLI changes working directory; making it harder to run scripts
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: JBoss Operations Network
Classification: JBoss
Component: CLI
Version: JON 3.2
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: ---
: JON 3.3.0
Assignee: RHQ Project Maintainer
QA Contact: Mike Foley
URL:
Whiteboard:
Depends On: 959603
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-12-12 22:28 UTC by Lukas Krejci
Modified: 2015-01-05 16:42 UTC (History)
5 users (show)

Fixed In Version:
Clone Of: 959603
Environment:
Last Closed: 2015-01-05 16:08:46 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Lukas Krejci 2013-12-12 22:28:09 UTC
+++ This bug was initially created as a clone of Bug #959603 +++

There is no reason for the CLI to change the working directory.

This means execution of scripts outside of the RHQ_CLI_HOME directory requires a user to put in the full path of the script, even though it is in the working directory.

The solution is to simply remove the 'cd' commands like so:

--- ../../rhq-remoting-cli-4.4.0/bin/rhq-cli.sh	2012-08-09 12:43:17.000000000 -0700
+++ rhq-cli.sh	2013-05-03 16:42:18.000000000 -0700
@@ -50,15 +50,13 @@
 fi
 
 if [ -z "$RHQ_CLI_HOME" ]; then
-   cd "${RHQ_CLI_BIN_DIR_PATH}/.."
-else
-   cd "${RHQ_CLI_HOME}" || {
-      echo "Cannot go to the RHQ_CLI_HOME directory: ${RHQ_CLI_HOME}"
-      exit 1
-      }
+   RHQ_CLI_HOME="${RHQ_CLI_BIN_DIR_PATH}/.."
 fi
 
-RHQ_CLI_HOME=`pwd`
+test -d "${RHQ_CLI_HOME}" || {
+  echo "Cannot go to the RHQ_CLI_HOME directory: ${RHQ_CLI_HOME}"
+  exit 1
+  }
 
 debug_msg "RHQ_CLI_HOME: $RHQ_CLI_HOME"

--- Additional comment from Heiko W. Rupp on 2013-06-17 07:14:15 EDT ---

Lukas,
can you please have a look? I fear that change is less than minor due to possible behavior change in downstream JON

--- Additional comment from Lukas Krejci on 2013-07-01 12:09:32 EDT ---

I agree that this behavior is somewhat confusing. That said, we've been shipping the scripts like that since the very beginning and people probably have worked around that behavior.

I am actually not sure why that behavior is in place, it seems to just have been copied from the agent start up script (where I am not sure about the behavior either).

But because of the backwards compatibility reasons I think we should not change this behavior by default.

What I think we MIGHT do though is the following:

1) Make the changing of the directory optional based on (yet another) env var: RHQ_CLI_CHANGE_DIR_ON_START
2) Put this env variable inside rhq-cli-env.sh (uncommented)
3) Parametrize that file during the maven build
4) In RHQ, let it default to false
5) JBoss ON build can customize it to true

That way we can make the switch to the new behavior immediately in RHQ but provide a backwards-compatible behavior for people using JON as well as a way of swapping that behavior either by users themselves or at some future release by us.

--- Additional comment from Lukas Krejci on 2013-12-12 17:16:06 EST ---

commit f35bbe1a20a775c8273b551a924261e254dd199d
Author: Lukas Krejci <lkrejci>
Date:   Thu Dec 12 23:10:14 2013 +0100

    [BZ 959603] - Don't change CWD on CLI startup.
    
    Since the very beginning of CLI, RHQ always changed the CWD to
    $RHQ_CLI_HOME when starting up, which is rather strange and
    non-standard.
    
    To keep the backwards compatibility, the behavior can be toggled on
    or off.
    
    The default behavior can be changed in the build by setting the
    
    rhq.cli.change-dir-on-start-default
    
    property. In RHQ, this defaults to "false", causing RHQ to NOT change
    directories when starting up the CLI anymore.
    
    Further, the behavior can be toggled by the user by setting the
    RHQ_CLI_CHANGE_DIR_ON_START environment variable to "true" (or any
    other value but "false" actually) or "false" explicitly.
    
    Additionally, a new environment variable called "RHQ_CLI_MODULES_DIR"
    was added. This was necessary to not break the loading of the
    provided CommonJS modules available in the
    $RHQ_CLI_HOME/samples/modules directory if the CLI was started from
    another directory.
    By adding the new RHQ_CLI_MODULES_DIR, which is initialized to the
    correct value if not provided externally, we correctly load the
    sample modules with the additional benefit of easier change of the
    modules location for the user (previously this was only possible
    through
    RHQ_CLI_ADDITIONAL_JAVA_OPTS="-Drhq.scripting.modules.root-dir=..."
    , while now one only needs RHQ_CLI_MODULES_DIR=...).

Comment 1 Lukas Krejci 2013-12-12 22:31:22 UTC
We need to decide whether to follow the new behavior of RHQ (i.e. NOT change the current working directory when running CLI) or to keep strict backwards compatibility and do not do it in JBoss ON (a build flag is enough for this as described in the commit message above).

We also need to put the new env variables to docs.

Comment 4 Larry O'Leary 2015-01-05 16:08:46 UTC
This was fixed in upstream RHQ 4.10 release. Therefore, the fix was inherited in JBoss ON 3.3. Closing as fixed upstream.

Comment 5 Lukas Krejci 2015-01-05 16:42:11 UTC
Hmm...

Just for the record, rhq-cli-env.(sh|bat) contains a switch to restore the original behavior - the RHQ_CLI_CHANGE_DIR_ON_START variable.

The default in JON3.3 indeed seems to NOT change directories anymore.


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