Repository: nifi
Updated Branches:
  refs/heads/master a8b8f1530 -> 4f49095d7


NIFI-3294 Adjusting nifi.sh to invoke nifi-env.sh when running as another user 
such that properties are preserved across environments.

This closes #1405.

Signed-off-by: Aldrin Piri <ald...@apache.org>
Signed-off-by: ijokarumawak <ijokaruma...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/4f49095d
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/4f49095d
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/4f49095d

Branch: refs/heads/master
Commit: 4f49095d750f55d05eaf75d6e0b60f778eef8513
Parents: a8b8f15
Author: Aldrin Piri <ald...@apache.org>
Authored: Fri Jan 6 23:20:54 2017 -0500
Committer: ijokarumawak <ijokaruma...@apache.org>
Committed: Mon Feb 20 11:04:11 2017 +0900

----------------------------------------------------------------------
 .../src/main/resources/bin/nifi.sh              | 38 ++++++++++----------
 1 file changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/4f49095d/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh
index 9a7d2a9..8834cbc 100755
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh
@@ -38,12 +38,12 @@ done
 
 # Compute the canonicalized name by finding the physical path
 # for the directory we're in and appending the target file.
-PHYS_DIR=`pwd -P`
+PHYS_DIR=$(pwd -P)
 
 SCRIPT_DIR=$PHYS_DIR
 PROGNAME=$(basename "$0")
 
-. "$SCRIPT_DIR"/nifi-env.sh
+. "${SCRIPT_DIR}/nifi-env.sh"
 
 
 
@@ -234,15 +234,14 @@ run() {
     BOOTSTRAP_CONF="${BOOTSTRAP_CONF_DIR}/bootstrap.conf";
     BOOTSTRAP_LIBS="${NIFI_HOME}/lib/bootstrap/*"
 
-    run_as=$(grep '^\s*run.as' "${BOOTSTRAP_CONF}" | cut -d'=' -f2)
+    run_as_user=$(grep '^\s*run.as' "${BOOTSTRAP_CONF}" | cut -d'=' -f2)
     # If the run as user is the same as that starting the process, ignore this 
configuration
-    if [ "$run_as" = "$(whoami)" ]; then
-        unset run_as
+    if [ "${run_as_user}" = "$(whoami)" ]; then
+        unset run_as_user
     fi
 
-    sudo_cmd_prefix=""
     if $cygwin; then
-        if [ -n "${run_as}" ]; then
+        if [ -n "${run_as_user}" ]; then
             echo "The run.as option is not supported in a Cygwin environment. 
Exiting."
             exit 1
         fi;
@@ -259,11 +258,9 @@ run() {
             BOOTSTRAP_CLASSPATH="${TOOLS_JAR};${BOOTSTRAP_CLASSPATH}"
         fi
     else
-        if [ -n "${run_as}" ]; then
-            if id -u "${run_as}" >/dev/null 2>&1; then
-                sudo_cmd_prefix="sudo -u ${run_as}"
-            else
-                echo "The specified run.as user ${run_as} does not exist. 
Exiting."
+        if [ -n "${run_as_user}" ]; then
+            if ! id -u "${run_as_user}" >/dev/null 2>&1; then
+                echo "The specified run.as user ${run_as_user} does not exist. 
Exiting."
                 exit 1
             fi
         fi;
@@ -284,18 +281,21 @@ run() {
     # all other commands will terminate quickly so want to just wait for them
 
     #setup directory parameters
-    
BOOTSTRAP_LOG_PARAMS="-Dorg.apache.nifi.bootstrap.config.log.dir="\""${NIFI_LOG_DIR}"\"""
-    
BOOTSTRAP_PID_PARAMS="-Dorg.apache.nifi.bootstrap.config.pid.dir="\""${NIFI_PID_DIR}"\"""
-    
BOOTSTRAP_CONF_PARAMS="-Dorg.apache.nifi.bootstrap.config.file="\""${BOOTSTRAP_CONF}"\"""
+    
BOOTSTRAP_LOG_PARAMS="-Dorg.apache.nifi.bootstrap.config.log.dir='${NIFI_LOG_DIR}'"
+    
BOOTSTRAP_PID_PARAMS="-Dorg.apache.nifi.bootstrap.config.pid.dir='${NIFI_PID_DIR}'"
+    
BOOTSTRAP_CONF_PARAMS="-Dorg.apache.nifi.bootstrap.config.file='${BOOTSTRAP_CONF}'"
 
     BOOTSTRAP_DIR_PARAMS="${BOOTSTRAP_LOG_PARAMS} ${BOOTSTRAP_PID_PARAMS} 
${BOOTSTRAP_CONF_PARAMS}"
-
-    RUN_NIFI_CMD="cd "\""${NIFI_HOME}"\"" && exec ${sudo_cmd_prefix} 
"\""${JAVA}"\"" -cp "\""${BOOTSTRAP_CLASSPATH}"\"" -Xms12m -Xmx24m 
${BOOTSTRAP_DIR_PARAMS}  org.apache.nifi.bootstrap.RunNiFi"
+    run_nifi_cmd="exec '${JAVA}' -cp '${BOOTSTRAP_CLASSPATH}' -Xms12m -Xmx24m 
${BOOTSTRAP_DIR_PARAMS} org.apache.nifi.bootstrap.RunNiFi $@"
+    if [ -n "${run_as_user}" ]; then
+      # Provide SCRIPT_DIR and execute nifi-env for the run.as user command
+      run_nifi_cmd="sudo -u ${run_as_user} sh -c \"SCRIPT_DIR='${SCRIPT_DIR}' 
&& . '${SCRIPT_DIR}/nifi-env.sh' && ${run_nifi_cmd}\""
+    fi
 
     if [ "$1" = "start" ]; then
-        (eval $RUN_NIFI_CMD $@ &)
+        ( eval "cd ${NIFI_HOME} && ${run_nifi_cmd}" & )
     else
-        eval $RUN_NIFI_CMD $@
+        eval "cd ${NIFI_HOME} && ${run_nifi_cmd}"
     fi
     EXIT_STATUS=$?
 

Reply via email to