From 0c4628d8e795c73e646387547070697e80c0f7f9 Mon Sep 17 00:00:00 2001 From: Siyao Meng Date: Sat, 10 Aug 2019 05:54:20 -0700 Subject: [PATCH 1/2] HADOOP-16276. Fix jsvc startup command in hadoop-functions.sh due to jsvc >= 1.0.11 changed default current working directory Rebased HADOOP-16276.003.patch onto trunk after HADOOP-16289 is committed. Change-Id: I65ae7dcc142b8416bc28698ae88c96437181bb4d --- .../src/main/bin/hadoop-functions.sh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh index 484fe2302f9ba..b58f1822add71 100755 --- a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh +++ b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh @@ -1878,6 +1878,18 @@ function hadoop_start_daemon_wrapper return 0 } +## @description Test if versionA is lower than versionB +## @audience private +## @stability evolving +## @replaceable yes +## @param versionA +## @param versionB +function is_lower_version +{ + # Use version sort + test "$(printf '%s\n' "$@" | sort -V | head -n1)" != "$1"; +} + ## @description Start a privileged daemon in the foreground. ## @audience private ## @stability evolving @@ -1921,6 +1933,31 @@ function hadoop_start_secure_daemon exit 1 fi + if [[ -z "${HADOOP_DAEMON_JSVC_EXTRA_OPTS}" ]]; then + # If HADOOP_DAEMON_JSVC_EXTRA_OPTS is not set + # Default jsvc option to be added for all jsvc >= 1.0.11 + local jsvccwdopt="-cwd ." + # Detect local jsvc version + jsvcver=$(${jsvc} -help | tail -n3 | head -n1 | awk -F' ' '{print $NF}') + # The lowest jsvc version that introduced cwd option + jsvcverhascwd=1.0.11 + + # The reason to put old version (no cwd option) in true branch is in case + # of a future jsvc release breaking the above jsvc version detection, + # it should go to the false branch. + if is_lower_version ${jsvcverhascwd} ${jsvcver}; then + hadoop_debug "jsvc ${jsvcver} < ${jsvcverhascwd}." \ + "No need to add jsvc cwd option. See HADOOP-16276 for details." + else + hadoop_debug "jsvc ${jsvcver} >= ${jsvcverhascwd}." \ + "Adding jsvc cwd option. See HADOOP-16276 for details." + HADOOP_DAEMON_JSVC_EXTRA_OPTS="${jsvccwdopt}" + fi + else + hadoop_debug "HADOOP_DAEMON_JSVC_EXTRA_OPTS is set." \ + "Ignoring auto cwd option selection based on jsvc version." + fi + # note that shellcheck will throw a # bogus for-our-use-case 2086 here. # it doesn't properly support multi-line situations From 9f8544d7b7b95847ab373f4c51f71b056e056b16 Mon Sep 17 00:00:00 2001 From: Siyao Meng Date: Sat, 10 Aug 2019 06:06:20 -0700 Subject: [PATCH 2/2] Change auto-detect logic, now based on grep. Thanks Daniel for the suggestion. Change-Id: Iaa91dacabcc1e985bef1c28fcb718a5436e4e7ff --- .../src/main/bin/hadoop-functions.sh | 37 ++++--------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh index b58f1822add71..eb7285fb4e667 100755 --- a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh +++ b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh @@ -1878,18 +1878,6 @@ function hadoop_start_daemon_wrapper return 0 } -## @description Test if versionA is lower than versionB -## @audience private -## @stability evolving -## @replaceable yes -## @param versionA -## @param versionB -function is_lower_version -{ - # Use version sort - test "$(printf '%s\n' "$@" | sort -V | head -n1)" != "$1"; -} - ## @description Start a privileged daemon in the foreground. ## @audience private ## @stability evolving @@ -1935,27 +1923,18 @@ function hadoop_start_secure_daemon if [[ -z "${HADOOP_DAEMON_JSVC_EXTRA_OPTS}" ]]; then # If HADOOP_DAEMON_JSVC_EXTRA_OPTS is not set - # Default jsvc option to be added for all jsvc >= 1.0.11 - local jsvccwdopt="-cwd ." - # Detect local jsvc version - jsvcver=$(${jsvc} -help | tail -n3 | head -n1 | awk -F' ' '{print $NF}') - # The lowest jsvc version that introduced cwd option - jsvcverhascwd=1.0.11 - - # The reason to put old version (no cwd option) in true branch is in case - # of a future jsvc release breaking the above jsvc version detection, - # it should go to the false branch. - if is_lower_version ${jsvcverhascwd} ${jsvcver}; then - hadoop_debug "jsvc ${jsvcver} < ${jsvcverhascwd}." \ - "No need to add jsvc cwd option. See HADOOP-16276 for details." + if ${jsvc} -help | grep -q "\-cwd"; then + # Check if jsvc -help has entry for option -cwd + hadoop_debug "Your jsvc supports -cwd option." \ + "Adding option '-cwd .'. See HADOOP-16276 for details." + HADOOP_DAEMON_JSVC_EXTRA_OPTS="-cwd ." else - hadoop_debug "jsvc ${jsvcver} >= ${jsvcverhascwd}." \ - "Adding jsvc cwd option. See HADOOP-16276 for details." - HADOOP_DAEMON_JSVC_EXTRA_OPTS="${jsvccwdopt}" + hadoop_debug "Your jsvc doesn't support -cwd option." \ + "No need to add option '-cwd .'. See HADOOP-16276 for details." fi else hadoop_debug "HADOOP_DAEMON_JSVC_EXTRA_OPTS is set." \ - "Ignoring auto cwd option selection based on jsvc version." + "Ignoring jsvc -cwd option detection and addition." fi # note that shellcheck will throw a