Bug 959603 - CLI changes working directory; making it harder to run scripts
Summary: CLI changes working directory; making it harder to run scripts
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: RHQ Project
Classification: Other
Component: CLI
Version: 4.5
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
: RHQ 4.10
Assignee: Lukas Krejci
QA Contact: Mike Foley
URL:
Whiteboard:
Depends On:
Blocks: 1042495
TreeView+ depends on / blocked
 
Reported: 2013-05-03 23:44 UTC by Elias Ross
Modified: 2014-04-23 12:29 UTC (History)
1 user (show)

Fixed In Version:
Clone Of:
: 1042495 (view as bug list)
Environment:
Last Closed: 2014-04-23 12:29:55 UTC
Embargoed:


Attachments (Terms of Use)

Description Elias Ross 2013-05-03 23:44:52 UTC
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"

Comment 1 Heiko W. Rupp 2013-06-17 11:14:15 UTC
Lukas,
can you please have a look? I fear that change is less than minor due to possible behavior change in downstream JON

Comment 2 Lukas Krejci 2013-07-01 16:09:32 UTC
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.

Comment 3 Lukas Krejci 2013-12-12 22:16:06 UTC
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 4 Heiko W. Rupp 2014-04-23 12:29:55 UTC
Bulk closing of 4.10 issues.

If an issue is not solved for you, please open a new BZ (or clone the existing one) with a version designator of 4.10.


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