You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by kr...@apache.org on 2019/03/11 14:08:57 UTC

[knox] branch master updated: KNOX-1774 - Introduce environment variables in gateway/knoxcli/ldap/knoxshell scripts for customization (#65)

This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new dea6c98  KNOX-1774 - Introduce environment variables in gateway/knoxcli/ldap/knoxshell scripts for customization (#65)
dea6c98 is described below

commit dea6c98ee67df8a4695789e33b990b86a2d9ce11
Author: Sandor Molnar <sm...@apache.org>
AuthorDate: Mon Mar 11 15:08:52 2019 +0100

    KNOX-1774 - Introduce environment variables in gateway/knoxcli/ldap/knoxshell scripts for customization (#65)
---
 gateway-release-common/home/bin/knox-env.sh        | 115 +++++++++++++++++++++
 .../home/bin/knox-functions.sh                     |  44 +++++++-
 gateway-release-common/pom.xml                     |  32 ++++++
 gateway-release/home/bin/gateway.sh                |  40 ++++---
 gateway-release/home/bin/knox-env.sh               |  68 ------------
 gateway-release/home/bin/knoxcli.sh                |  34 ++----
 gateway-release/home/bin/ldap.sh                   |  70 +++++--------
 gateway-release/pom.xml                            |  24 +++++
 gateway-release/src/assembly.xml                   |   8 ++
 .../gateway/config/impl/GatewayConfigImpl.java     |  71 +++++++------
 gateway-shell-release/home/bin/knoxshell.sh        |  26 ++---
 gateway-shell-release/pom.xml                      |  24 +++++
 gateway-shell-release/src/assembly.xml             |   8 ++
 .../apache/knox/gateway/config/GatewayConfig.java  |  16 ++-
 pom.xml                                            |   6 ++
 15 files changed, 381 insertions(+), 205 deletions(-)

diff --git a/gateway-release-common/home/bin/knox-env.sh b/gateway-release-common/home/bin/knox-env.sh
new file mode 100644
index 0000000..2979a63
--- /dev/null
+++ b/gateway-release-common/home/bin/knox-env.sh
@@ -0,0 +1,115 @@
+#!/usr/bin/env bash
+
+#
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+
+######################################################
+#### GATEWAY SERVER RELATED ENVIRONMENT VARIABLES ####
+######################################################
+
+## KNOX_GATEWAY_CONF_DIR indicates where the gateway server should read its configuration from.
+## Defaults to {GATEWAY_HOME}/conf
+# export KNOX_GATEWAY_CONF_DIR=""
+
+## KNOX_GATEWAY_DATA_DIR indicates where the gateway server should find it's data directory.
+## This folder contains security, deployment and topology specific artifacts and requires read/write access at runtime.
+## Defaults to {GATEWAY_HOME}/data
+# export KNOX_GATEWAY_DATA_DIR=""
+
+## KNOX_GATEWAY_LOG_DIR indicates where the gateway server should write its own error/standard output messages to.
+## Defaults to {GATEWAY_HOME}/logs
+# export KNOX_GATEWAY_LOG_DIR=""
+
+## KNOX_GATEWAY_LOG_OPTS is a placeholder to set the gateway server's Log4j options (e.g. "-Dlog4j.debug -Dlog4j.configuration=foobar.xml")
+## Defaults to an empty string
+# export KNOX_GATEWAY_LOG_OPTS=""
+
+## KNOX_GATEWAY_MEM_OPTS is a placeholder to allow customization of the gateway server's JVM memory settings (e.g. "-Xms512m -Xmx1024m")
+## Defaults to an empty string
+# export KNOX_GATEWAY_MEM_OPTS=""
+
+## KNOX_GATEWAY_DBG_OPTS is a placeholder to allow customization of the gateway server's JVM debug settings (e.g. "-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y")
+## Defaults to an empty string
+# export KNOX_GATEWAY_DBG_OPTS=""
+
+## KNOX_GATEWAY_JAVA_LIB_PATH allows customization of java.library.path System property, which is used by the gateway's JVM to search native libraries.
+## defaults to {GATEWAY_HOME}/ext/native
+# export KNOX_GATEWAY_JAVA_LIB_PATH=""
+
+## KNOX_GATEWAY_PID_DIR indicates the folder where the gateway server's places its PID file (in case it's being executed in the background).
+## Since status check relies on the PID file being read by the script it's very important to have read/write access at runtime to this folder.
+## Defaults to {GATEWAY_HOME}/pids
+# export KNOX_GATEWAY_PID_DIR=""
+
+
+################################################
+#### KNOX-CLI RELATED ENVIRONMENT VARIABLES ####
+################################################
+
+## KNOX_CLI_LOG_OPTS is a placeholder to set KnoxCLI's Log4j options (e.g. "-Dlog4j.debug -Dlog4j.configuration=foobar.xml")
+## Defaults to an empty string
+# export KNOX_CLI_LOG_OPTS=""
+
+## KNOX_CLI_MEM_OPTS is a placeholder to allow customization of KnoxCLI's JVM memory settings (e.g. "-Xms512m -Xmx1024m")
+## Defaults to an empty string
+# export KNOX_CLI_MEM_OPTS=""
+
+## KNOX_CLI_DBG_OPTS is a placeholder to allow customization of KnoxCLI's JVM debug settings (e.g. "-Xdebug -Xrunjdwp:transport=dt_socket,address=5006,server=y,suspend=y")
+## Defaults to an empty string
+# export KNOX_CLI_DBG_OPTS=""
+
+
+########################################################
+#### KNOX LDAP SERVER RELATED ENVIRONMENT VARIABLES ####
+########################################################
+
+## KNOX_LDAP_CONF_DIR indicates where the test LDAP server should read its configuration from (including user.ldif)
+## Defaults to {GATEWAY_HOME}/conf
+# export KNOX_LDAP_CONF_DIR=""
+
+## KNOX_LDAP_LOG_DIR indicates where the test LDAP server should write its own error/standard output messages to.
+## Defaults to {GATEWAY_HOME}/logs
+# export KNOX_LDAP_LOG_DIR=""
+
+## KNOX_LDAP_LOG_OPTS is a placeholder to set the test LDAP server's Log4j options (e.g. "-Dlog4j.debug -Dlog4j.configuration=foobar.xml")
+## Defaults to an empty string
+# export KNOX_LDAP_LOG_OPTS=""
+
+## KNOX_LDAP_MEM_OPTS is a placeholder to allow customization of the test LDAP server's JVM memory settings (e.g. "-Xms512m -Xmx1024m")
+## Defaults to an empty string
+# export KNOX_LDAP_MEM_OPTS=""
+
+## KNOX_LDAP_DBG_OPTS is a placeholder to allow customization of the test LDAP server's JVM debug settings (e.g. "-Xdebug -Xrunjdwp:transport=dt_socket,address=5007,server=y,suspend=y")
+## Defaults to an empty string
+# export KNOX_LDAP_DBG_OPTS=""
+
+
+##################################################
+#### KNOX-SHELL RELATED ENVIRONMENT VARIABLES ####
+##################################################
+
+## KNOX_SHELL_LOG_OPTS is a placeholder to set KnoxShell's Log4j options (e.g. "-Dlog4j.debug -Dlog4j.configuration=foobar.xml")
+## Defaults to an empty string
+# export KNOX_SHELL_LOG_OPTS=""
+
+## KNOX_SHELL_MEM_OPTS is a placeholder to allow customization of KnoxShell's JVM memory settings (e.g. "-Xms512m -Xmx1024m")
+## Defaults to an empty string
+# export KNOX_SHELL_MEM_OPTS=""
+
+## KNOX_SHELL_DBG_OPTS is a placeholder to allow customization of KnoxShell's JVM debug settings (e.g. "-Xdebug -Xrunjdwp:transport=dt_socket,address=5008,server=y,suspend=y")
+## Defaults to an empty string
+# export KNOX_SHELL_DBG_OPTS=""
diff --git a/gateway-shell-release/home/bin/knox-env.sh b/gateway-release-common/home/bin/knox-functions.sh
similarity index 68%
rename from gateway-shell-release/home/bin/knox-env.sh
rename to gateway-release-common/home/bin/knox-functions.sh
index 1876a5d..7a8207c 100644
--- a/gateway-shell-release/home/bin/knox-env.sh
+++ b/gateway-release-common/home/bin/knox-functions.sh
@@ -17,8 +17,6 @@
 #  limitations under the License.
 #
 
-ENV_PID_DIR=""
-
 JAVA_VERSION_PATTERNS=( "1.6.0_31/bin/java$" "1.6.0_.*/bin/java$" "1.6.0.*/bin/java$" "1.6\..*/bin/java$" "/bin/java$" )
 
 function findJava() {
@@ -60,9 +58,49 @@ function findJava() {
   fi
 }
 
-findJava
+function checkJava() {
+  findJava
 
   if [[ -z $JAVA ]]; then
     echo "Warning: JAVA is not set and could not be found." 1>&2
   fi
+}
+
+function printEnv() {
+    if [ ! -z "$APP_CONF_DIR" ]; then
+      echo "APP_CONF_DIR = $APP_CONF_DIR"
+    fi
+    
+    if [ ! -z "$APP_LOG_DIR" ]; then
+      echo "APP_LOG_DIR = $APP_LOG_DIR"
+    fi
+
+    if [ ! -z "$APP_DATA_DIR" ]; then
+      echo "APP_DATA_DIR = $APP_DATA_DIR"
+    fi
+
+    if [ ! -z "$APP_MEM_OPTS" ]; then
+      echo "APP_MEM_OPTS = $APP_MEM_OPTS"
+    fi
+
+    if [ ! -z "$APP_LOG_OPTS" ]; then
+      echo "APP_LOG_OPTS = $APP_LOG_OPTS"
+    fi
+
+    if [ ! -z "$APP_DBG_OPTS" ]; then
+      echo "APP_DBG_OPTS = $APP_DBG_OPTS"
+    fi
+
+    if [ ! -z "$APP_PID_DIR" ]; then
+      echo "APP_PID_DIR = $APP_PID_DIR"
+    fi
+
+    if [ ! -z "$APP_JAVA_LIB_PATH" ]; then
+      echo "APP_JAVA_LIB_PATH = $APP_JAVA_LIB_PATH"
+    fi
+
+    if [ ! -z "$APP_JAR" ]; then
+      echo "APP_JAR = $APP_JAR"
+    fi
+}
 
diff --git a/gateway-release-common/pom.xml b/gateway-release-common/pom.xml
new file mode 100644
index 0000000..b4c9efc
--- /dev/null
+++ b/gateway-release-common/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+        <groupId>org.apache.knox</groupId>
+        <artifactId>gateway</artifactId>
+        <version>1.3.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>gateway-release-common</artifactId>
+  <packaging>pom</packaging>
+
+  <name>gateway-release-common</name>
+  <description>Contains common resources to be used by released artifacts</description>
+</project>
diff --git a/gateway-release/home/bin/gateway.sh b/gateway-release/home/bin/gateway.sh
index 6c0ac16..8f0ba34 100755
--- a/gateway-release/home/bin/gateway.sh
+++ b/gateway-release/home/bin/gateway.sh
@@ -29,41 +29,46 @@ APP_BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 # Setup the common environment
 . $APP_BIN_DIR/knox-env.sh
 
+# Source common functions
+. $APP_BIN_DIR/knox-functions.sh
+
 # The app's jar name
 APP_JAR="$APP_BIN_DIR/gateway.jar"
 
-# The apps home dir
+# The app's home dir
 APP_HOME_DIR=`dirname $APP_BIN_DIR`
 
-# The apps home dir
-APP_CONF_DIR="$APP_HOME_DIR/conf"
+# The app's conf dir
+DEFAULT_APP_CONF_DIR="$APP_HOME_DIR/conf"
+APP_CONF_DIR=${KNOX_GATEWAY_CONF_DIR:-$DEFAULT_APP_CONF_DIR}
 
-# The apps data dir
-APP_DATA_DIR="$APP_HOME_DIR/data"
+# The app's data dir
+DEFAULT_APP_DATA_DIR="$APP_HOME_DIR/data"
+APP_DATA_DIR=${KNOX_GATEWAY_DATA_DIR:-$DEFAULT_APP_DATA_DIR}
 
 # The app's log dir
-APP_LOG_DIR="$APP_HOME_DIR/logs"
+DEFAULT_APP_LOG_DIR="$APP_HOME_DIR/logs"
+APP_LOG_DIR=${KNOX_GATEWAY_LOG_DIR:-$DEFAULT_APP_LOG_DIR}
 
 # The app's logging options
-APP_LOG_OPTS=""
+APP_LOG_OPTS="$KNOX_GATEWAY_LOG_OPTS"
 
 # The app's memory options
-APP_MEM_OPTS=""
+APP_MEM_OPTS="$KNOX_GATEWAY_MEM_OPTS"
 
 # The app's debugging options
-APP_DBG_OPTS=""
+APP_DBG_OPTS="$KNOX_GATEWAY_DBG_OPTS"
 
 # The app's PID
 APP_PID=0
 
 #dynamic library path
-APP_JAVA_LIB_PATH="-Djava.library.path=$APP_HOME_DIR/ext/native"
-
-# Start, stop, status, clean or setup
-APP_LAUNCH_CMD=$1
+DEFAULT_JAVA_LIB_PATH="-Djava.library.path=$APP_HOME_DIR/ext/native"
+APP_JAVA_LIB_PATH=${KNOX_GATEWAY_JAVA_LIB_PATH:-$DEFAULT_JAVA_LIB_PATH}
 
 # Name of PID file
-[[ $ENV_PID_DIR ]] && APP_PID_DIR="$ENV_PID_DIR" || APP_PID_DIR="$APP_HOME_DIR/pids"
+DEFAULT_APP_PID_DIR="$APP_HOME_DIR/pids"
+APP_PID_DIR=${KNOX_GATEWAY_PID_DIR:-$DEFAULT_APP_PID_DIR}
 APP_PID_FILE="$APP_PID_DIR/$APP_NAME.pid"
 
 # Name of LOG/OUT/ERR file
@@ -77,11 +82,16 @@ APP_START_WAIT_TIME=2
 APP_KILL_WAIT_TIME=10
 
 function main {
+   checkJava
+
    case "$1" in
       setup)
          setupEnv
          ;;
       start)
+         if [ "$2" = "--printEnv" ]; then
+           printEnv
+         fi
          appStart
          ;;
       stop)   
@@ -307,4 +317,4 @@ function printHelp {
 }
 
 #Starting main
-main $APP_LAUNCH_CMD
+main $@
diff --git a/gateway-release/home/bin/knox-env.sh b/gateway-release/home/bin/knox-env.sh
deleted file mode 100644
index 1876a5d..0000000
--- a/gateway-release/home/bin/knox-env.sh
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/env bash
-
-#
-#  Licensed to the Apache Software Foundation (ASF) under one or more
-#  contributor license agreements.  See the NOTICE file distributed with
-#  this work for additional information regarding copyright ownership.
-#  The ASF licenses this file to You under the Apache License, Version 2.0
-#  (the "License"); you may not use this file except in compliance with
-#  the License.  You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-#
-
-ENV_PID_DIR=""
-
-JAVA_VERSION_PATTERNS=( "1.6.0_31/bin/java$" "1.6.0_.*/bin/java$" "1.6.0.*/bin/java$" "1.6\..*/bin/java$" "/bin/java$" )
-
-function findJava() {
-  # Check to make sure any existing JAVA var is valid.
-  if [ "$JAVA" != "" ]; then
-    if [ ! -x "$JAVA" ]; then
-      JAVA=""
-    fi
-  fi
-  
-  # Try to use JAVA_HOME to find java.
-  if [ "$JAVA" == "" ]; then
-    if [ "$JAVA_HOME" != "" ]; then
-      JAVA=$JAVA_HOME/bin/java
-      if [ ! -x "$JAVA" ]; then
-        JAVA=""
-      fi
-    fi
-  fi
-
-  # Try to find java on PATH.
-  if [ "$JAVA" == "" ]; then
-    JAVA=`which java 2>/dev/null`
-    if [ ! -x "$JAVA" ]; then
-      JAVA=""
-    fi
-  fi
-
-  # Use the search patterns to find java.
-  if [ "$JAVA" == "" ]; then
-    for pattern in "${JAVA_VERSION_PATTERNS[@]}"; do
-      JAVA=( $(find /usr -executable -name java -print 2> /dev/null | grep "$pattern" | head -n 1 ) )
-      if [ -x "$JAVA" ]; then
-        break
-      else
-        JAVA=""
-      fi
-    done
-  fi
-}
-
-findJava
-
-  if [[ -z $JAVA ]]; then
-    echo "Warning: JAVA is not set and could not be found." 1>&2
-  fi
-
diff --git a/gateway-release/home/bin/knoxcli.sh b/gateway-release/home/bin/knoxcli.sh
index d01aa4e..c988a78 100755
--- a/gateway-release/home/bin/knoxcli.sh
+++ b/gateway-release/home/bin/knoxcli.sh
@@ -29,42 +29,20 @@ APP_BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 # The app's jar name
 APP_JAR="$APP_BIN_DIR/knoxcli.jar"
 
-# The apps home dir
-APP_HOME_DIR=`dirname $APP_BIN_DIR`
-
-# The apps home dir
-APP_CONF_DIR="$APP_HOME_DIR/conf"
-
-# The app's log dir
-APP_LOG_DIR="$APP_HOME_DIR/logs"
-
-# The app's logging options
-APP_LOG_OPTS=""
-
-# The app's memory options
-APP_MEM_OPTS=""
-
-# The app's debugging options
-APP_DBG_OPTS=""
-
-# Name of LOG/OUT/ERR file
-APP_OUT_FILE="$APP_LOG_DIR/$APP_NAME.out"
-APP_ERR_FILE="$APP_LOG_DIR/$APP_NAME.err"
-
 # Setup the common environment
 . $APP_BIN_DIR/knox-env.sh
 
+# Source common functions
+. $APP_BIN_DIR/knox-functions.sh
+
 function main {
+   checkJava
+
    #printf "Starting $APP_LABEL \n"
    #printf "$@"
-   
-   $JAVA $APP_MEM_OPTS $APP_DBG_OPTS $APP_LOG_OPTS -jar $APP_JAR $@ || exit 1
 
-   return 0
-}
+   $JAVA $KNOX_CLI_MEM_OPTS $KNOX_CLI_DBG_OPTS $KNOX_CLI_LOG_OPTS -jar $APP_JAR $@ || exit 1
 
-function printHelp {
-   $JAVA -jar $APP_JAR -help
    return 0
 }
 
diff --git a/gateway-release/home/bin/ldap.sh b/gateway-release/home/bin/ldap.sh
index 7c88957..bca41b7 100755
--- a/gateway-release/home/bin/ldap.sh
+++ b/gateway-release/home/bin/ldap.sh
@@ -17,50 +17,50 @@
 #  limitations under the License.
 #
 
-# App name
+# The app's label
 APP_LABEL=LDAP
 
-# App name
+# The app's name
 APP_NAME=ldap
 
-# App name
-APP_JAR_NAME=ldap.jar
-
 # start/stop script location
 APP_BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
+# The app's JAR name
+APP_JAR="$APP_BIN_DIR/ldap.jar"
+
 # Setup the common environment
 . $APP_BIN_DIR/knox-env.sh
 
-# The app's jar name
-APP_JAR="$APP_BIN_DIR/$APP_JAR_NAME"
+# Source common functions
+. $APP_BIN_DIR/knox-functions.sh
 
 # The app's home dir
 APP_HOME_DIR=`dirname $APP_BIN_DIR`
 
-# The apps home dir
-APP_CONF_DIR="$APP_HOME_DIR/conf"
+# The app's conf dir
+DEFAULT_APP_CONF_DIR="$APP_HOME_DIR/conf"
+APP_CONF_DIR=${KNOX_LDAP_CONF_DIR:-$DEFAULT_APP_CONF_DIR}
 
 # The app's log dir
-APP_LOG_DIR="$APP_HOME_DIR/logs"
+DEFAULT_APP_LOG_DIR="$APP_HOME_DIR/logs"
+APP_LOG_DIR=${KNOX_LDAP_LOG_DIR:-$DEFAULT_APP_LOG_DIR}
 
-# The app's Log4j options
-APP_LOG_OPTS=""
+# The app's logging options
+APP_LOG_OPTS="$KNOX_LDAP_LOG_OPTS"
 
 # The app's memory options
-APP_MEM_OPTS=""
+APP_MEM_OPTS="$KNOX_LDAP_MEM_OPTS"
 
 # The app's debugging options
-APP_DBG_OPTS=""
-
-# Start, stop, status, clean
-APP_LAUNCH_COMMAND=$1
+APP_DBG_OPTS="$KNOX_LDAP_DBG_OPTS"
 
 # The app's PID
 APP_PID=0
 
 # The name of the PID file
-[[ $ENV_PID_DIR ]] && APP_PID_DIR="$ENV_PID_DIR" || APP_PID_DIR="$APP_HOME_DIR/pids"
+DEFAULT_APP_PID_DIR="$APP_HOME_DIR/pids"
+APP_PID_DIR=${KNOX_LDAP_PID_DIR:-$DEFAULT_APP_PID_DIR}
 APP_PID_FILE="$APP_PID_DIR/$APP_NAME.pid"
 
 #Name of LOG/OUT/ERR file
@@ -74,8 +74,13 @@ APP_START_WAIT_TIME=2
 APP_KILL_WAIT_TIME=10
 
 function main {
+   checkJava
+
    case "$1" in
       start)  
+         if [ "$2" = "--printEnv" ]; then
+           printEnv
+         fi
          appStart
          ;;
       stop)   
@@ -97,7 +102,7 @@ function appStart {
    createLogFiles
 
    if [ "$LDAP_SERVER_RUN_IN_FOREGROUND" == true ]; then
-      $JAVA $APP_MEM_OPTS $APP_DBG_OPTS $APP_LOG_OPTS -jar $APP_JAR $APP_CONF_DIR >>$APP_OUT_FILE 2>>$APP_ERR_FILE
+      $JAVA $APP_MEM_OPTS $APP_DBG_OPTS $APP_LOG_OPTS -jar $APP_JAR $APP_CONF_DIR
    else
       getPID
       if [ $? -eq 0 ]; then
@@ -256,35 +261,10 @@ function deleteLogFiles {
      printf "Removed the $APP_LABEL ERR file: $APP_ERR_FILE.\n"
 }
 
-function setDirPermission {
-   local dirName=$1
-   local userName=$2
-
-   if [ ! -d "$dirName" ]; then mkdir -p $dirName; fi
-   if [ $? -ne 0 ]; then
-      printf "Can't access or create \"$dirName\" folder.\n"
-      exit 1
-   fi
-
-   chown -f $userName $dirName
-   if [ $? -ne 0 ]; then
-      printf "Can't change owner of \"$dirName\" folder to \"$userName\" user.\n"
-      exit 1
-   fi
-
-   chmod o=rwx $dirName 
-   if [ $? -ne 0 ]; then
-      printf "Can't grant rwx permission to \"$userName\" user on \"$dirName\".\n"
-      exit 1
-   fi
-
-   return 0
-}
-
 function printHelp {
    printf "Usage: $0 {start|stop|status|clean}\n"
    return 0
 }
 
 # Starting main
-main $APP_LAUNCH_COMMAND
+main $@
diff --git a/gateway-release/pom.xml b/gateway-release/pom.xml
index 0af744f..c55da16 100644
--- a/gateway-release/pom.xml
+++ b/gateway-release/pom.xml
@@ -35,6 +35,30 @@
             <build>
                 <plugins>
                     <plugin>
+                        <artifactId>maven-resources-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>copy-common-scripts</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>copy-resources</goal>
+                                </goals>
+                                <configuration>
+                                    <outputDirectory>${project.build.directory}/home/bin</outputDirectory>
+                                    <overwrite>true</overwrite>
+                                    <resources>
+                                        <resource>
+                                            <directory>${project.basedir}/../gateway-release-common/home/bin</directory>
+                                            <includes>
+                                                <include>*.sh</include>
+                                            </includes>
+                                        </resource>
+                                    </resources>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
                         <inherited>false</inherited>
                         <artifactId>maven-assembly-plugin</artifactId>
                         <executions>
diff --git a/gateway-release/src/assembly.xml b/gateway-release/src/assembly.xml
index dce4fed..b32192e 100644
--- a/gateway-release/src/assembly.xml
+++ b/gateway-release/src/assembly.xml
@@ -47,6 +47,14 @@
             <fileMode>0755</fileMode>
         </fileSet>
         <fileSet>
+            <directory>${project.build.directory}/home/bin/</directory>
+            <outputDirectory>bin</outputDirectory>
+            <includes>
+                <include>*.sh</include>
+            </includes>
+            <fileMode>0755</fileMode>
+        </fileSet>
+        <fileSet>
             <directory>..</directory>
             <outputDirectory></outputDirectory>
             <includes>
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
index 5bb5243..833de2b 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
@@ -89,10 +89,7 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
 
   private static final String DEFAULT_APPLICATIONS_DIR = "applications";
 
-  private static final String[] GATEWAY_CONFIG_FILENAMES = {
-      GATEWAY_CONFIG_DIR_PREFIX + "/" + GATEWAY_CONFIG_FILE_PREFIX + "-default.xml",
-      GATEWAY_CONFIG_DIR_PREFIX + "/" + GATEWAY_CONFIG_FILE_PREFIX + "-site.xml"
-  };
+  private static final String[] GATEWAY_CONFIG_FILENAMES = {GATEWAY_CONFIG_FILE_PREFIX + "-default.xml", GATEWAY_CONFIG_FILE_PREFIX + "-site.xml"};
 
   public static final String HTTP_HOST = GATEWAY_CONFIG_FILE_PREFIX + ".host";
   public static final String HTTP_PORT = GATEWAY_CONFIG_FILE_PREFIX + ".port";
@@ -259,18 +256,30 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
 
   @Override
   public String getGatewayConfDir() {
-    String value = getVar( GATEWAY_CONF_HOME_VAR, getGatewayHomeDir() + File.separator + "conf"  );
-    return FilenameUtils.normalize(value);
+    // 1st try: using the old style environment/system property name
+    @SuppressWarnings("deprecation")
+    String configDir = System.getProperty(GATEWAY_CONF_HOME_VAR, System.getenv(GATEWAY_CONF_HOME_VAR));
+
+    // 2nd try: using the new style environment/system property name or use the default value (relative to the GATEWAY_HOME)
+    if (StringUtils.isBlank(configDir)) {
+      configDir = getVar(KNOX_GATEWAY_CONF_DIR_VAR, getGatewayHomeDir() + File.separator + "conf");
+    }
+    return FilenameUtils.normalize(configDir);
   }
 
   @Override
   public String getGatewayDataDir() {
-    String systemValue =
-        System.getProperty(GATEWAY_DATA_HOME_VAR, System.getenv(GATEWAY_DATA_HOME_VAR));
-    String dataDir;
-    if (systemValue != null) {
-      dataDir = systemValue;
-    } else {
+    // 1st try: using the old style environment/system property name
+    @SuppressWarnings("deprecation")
+    String dataDir = System.getProperty(GATEWAY_DATA_HOME_VAR, System.getenv(GATEWAY_DATA_HOME_VAR));
+
+    // 2nd try: using the new style environment/system property name
+    if (StringUtils.isBlank(dataDir)) {
+      dataDir = System.getProperty(KNOX_GATEWAY_DATA_DIR, System.getenv(KNOX_GATEWAY_DATA_DIR));
+    }
+
+    // 3rd try: fetching it from gateway-[default|site].xml or use the default value (relative to the GATEWAY_HOME)
+    if (StringUtils.isBlank(dataDir)) {
       dataDir = get(DATA_DIR, getGatewayHomeDir() + File.separator + DEFAULT_DATA_DIR);
     }
     return FilenameUtils.normalize(dataDir);
@@ -302,8 +311,8 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
     }
 
     URL lastFileUrl = null;
-    for( String fileName : GATEWAY_CONFIG_FILENAMES ) {
-      lastFileUrl = loadConfig( fileName, lastFileUrl );
+    for (String fileName : GATEWAY_CONFIG_FILENAMES) {
+      lastFileUrl = loadConfig(fileName);
     }
 
     initGatewayHomeDir( lastFileUrl );
@@ -342,25 +351,29 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
     }
   }
 
-  // 1. GATEWAY_HOME system property
-  // 2. GATEWAY_HOME environment variable
-  // 3. user.dir system property
-  // 4. class path
-  private URL loadConfig( String fileName, URL lastFileUrl ) {
-    lastFileUrl = loadConfigFile( System.getProperty( GATEWAY_HOME_VAR ), fileName );
-    if( lastFileUrl == null ) {
-      lastFileUrl = loadConfigFile( System.getenv( GATEWAY_HOME_VAR ), fileName );
+  // 1. Pre-defined configuration directory
+  // 2. GATEWAY_HOME system property
+  // 3. GATEWAY_HOME environment variable
+  // 4. user.dir system property
+  // 5. class path
+  private URL loadConfig( String fileName) {
+    URL configFileUrl = loadConfigFile(getGatewayConfDir(), fileName);
+    if (configFileUrl == null ) {
+      configFileUrl = loadConfigFile( System.getProperty( GATEWAY_HOME_VAR ), GATEWAY_CONFIG_DIR_PREFIX + File.separator + fileName );
+    }
+    if( configFileUrl == null ) {
+      configFileUrl = loadConfigFile( System.getenv( GATEWAY_HOME_VAR ), GATEWAY_CONFIG_DIR_PREFIX + File.separator + fileName );
     }
-    if( lastFileUrl == null ) {
-      lastFileUrl = loadConfigFile( System.getProperty( "user.dir" ), fileName );
+    if( configFileUrl == null ) {
+      configFileUrl = loadConfigFile( System.getProperty( "user.dir" ), GATEWAY_CONFIG_DIR_PREFIX + File.separator + fileName );
     }
-    if( lastFileUrl == null ) {
-      lastFileUrl = loadConfigResource( fileName );
+    if( configFileUrl == null ) {
+      configFileUrl = loadConfigResource( GATEWAY_CONFIG_DIR_PREFIX + File.separator + fileName );
     }
-    if( lastFileUrl != null && !"file".equals( lastFileUrl.getProtocol() ) ) {
-      lastFileUrl = null;
+    if( configFileUrl != null && !"file".equals( configFileUrl.getProtocol() ) ) {
+      configFileUrl = null;
     }
-    return lastFileUrl;
+    return configFileUrl;
   }
 
   private URL loadConfigFile( String dir, String file ) {
diff --git a/gateway-shell-release/home/bin/knoxshell.sh b/gateway-shell-release/home/bin/knoxshell.sh
index f947aea..450d2b0 100755
--- a/gateway-shell-release/home/bin/knoxshell.sh
+++ b/gateway-shell-release/home/bin/knoxshell.sh
@@ -26,35 +26,31 @@ APP_NAME=knoxshell
 # Start/stop script location
 APP_BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
+# Setup the common environment
+. $APP_BIN_DIR/knox-env.sh
+
+# Source common functions
+. $APP_BIN_DIR/knox-functions.sh
+
 # The app's jar name
 APP_JAR="$APP_BIN_DIR/knoxshell.jar"
 
 # The apps home dir
 APP_HOME_DIR=`dirname $APP_BIN_DIR`
 
-# The apps home dir
-APP_CONF_DIR="$APP_HOME_DIR/conf"
-
-# The app's log dir
-APP_LOG_DIR="$APP_HOME_DIR/logs"
-
 # The app's logging options
-APP_LOG_OPTS=""
+APP_LOG_OPTS="$KNOX_SHELL_LOG_OPTS"
 
 # The app's memory options
-APP_MEM_OPTS=""
+APP_MEM_OPTS="$KNOX_SHELL_MEM_OPTS"
 
 # The app's debugging options
-APP_DBG_OPTS=""
+APP_DBG_OPTS="$KNOX_SHELL_DBG_OPTS"
 
-# Name of LOG/OUT/ERR file
-APP_OUT_FILE="$APP_LOG_DIR/$APP_NAME.out"
-APP_ERR_FILE="$APP_LOG_DIR/$APP_NAME.err"
-
-# Setup the common environment
-. $APP_BIN_DIR/knox-env.sh
 
 function main {
+   checkJava
+
    #printf "Starting $APP_LABEL \n"
    #printf "$@"
    case "$1" in
diff --git a/gateway-shell-release/pom.xml b/gateway-shell-release/pom.xml
index 2482a08..4ff1eef 100644
--- a/gateway-shell-release/pom.xml
+++ b/gateway-shell-release/pom.xml
@@ -59,6 +59,30 @@
             <build>
                 <plugins>
                     <plugin>
+                        <artifactId>maven-resources-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>copy-common-scripts</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>copy-resources</goal>
+                                </goals>
+                                <configuration>
+                                    <outputDirectory>${project.build.directory}/home/bin</outputDirectory>
+                                    <overwrite>true</overwrite>
+                                    <resources>
+                                        <resource>
+                                            <directory>${project.basedir}/../gateway-release-common/home/bin</directory>
+                                            <includes>
+                                                <include>*.sh</include>
+                                            </includes>
+                                        </resource>
+                                    </resources>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
                         <inherited>false</inherited>
                         <artifactId>maven-assembly-plugin</artifactId>
                         <executions>
diff --git a/gateway-shell-release/src/assembly.xml b/gateway-shell-release/src/assembly.xml
index 2445bfa..181f770 100644
--- a/gateway-shell-release/src/assembly.xml
+++ b/gateway-shell-release/src/assembly.xml
@@ -47,6 +47,14 @@
             <fileMode>0755</fileMode>
         </fileSet>
         <fileSet>
+            <directory>${project.build.directory}/home/bin/</directory>
+            <outputDirectory>bin</outputDirectory>
+            <includes>
+                <include>*.sh</include>
+            </includes>
+            <fileMode>0755</fileMode>
+        </fileSet>
+        <fileSet>
             <directory>..</directory>
             <outputDirectory></outputDirectory>
             <includes>
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
index 9a4e6e9..40bbc97 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
@@ -27,12 +27,24 @@ public interface GatewayConfig {
   // Used as the basis for any home directory that is not specified.
   String GATEWAY_HOME_VAR = "GATEWAY_HOME";
 
-  // Variable name for the location of configuration files edited by users
+  /**
+   * Variable name for the location of configuration files edited by users
+   *
+   * @deprecated use {@link GatewayConfig#KNOX_GATEWAY_CONF_DIR_VAR} instead
+   */
   String GATEWAY_CONF_HOME_VAR = "GATEWAY_CONF_HOME";
 
-  // Variable name for the location of data files generated by the gateway at runtime.
+  String KNOX_GATEWAY_CONF_DIR_VAR = "KNOX_GATEWAY_CONF_DIR";
+
+  /**
+   * Variable name for the location of data files generated by the gateway at runtime.
+   *
+   * @deprecated use {@link GatewayConfig#KNOX_GATEWAY_DATA_DIR} instead
+   */
   String GATEWAY_DATA_HOME_VAR = "GATEWAY_DATA_HOME";
 
+  String KNOX_GATEWAY_DATA_DIR = "KNOX_GATEWAY_DATA_DIR";
+
   String GATEWAY_CONFIG_ATTRIBUTE = "org.apache.knox.gateway.config";
   String HADOOP_KERBEROS_SECURED = "gateway.hadoop.kerberos.secured";
   String KRB5_CONFIG = "java.security.krb5.conf";
diff --git a/pom.xml b/pom.xml
index 5ee493c..8442cdd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -130,6 +130,7 @@
         <module>gateway-service-nifi</module>
         <module>gateway-docker</module>
         <module>gateway-service-hashicorp-vault</module>
+        <module>gateway-release-common</module>
     </modules>
 
     <properties>
@@ -1072,6 +1073,11 @@
                 <artifactId>gateway-service-hashicorp-vault</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.apache.knox</groupId>
+                <artifactId>gateway-release-common</artifactId>
+                <version>${project.version}</version>
+            </dependency>
 
             <dependency>
                 <groupId>org.glassfish.jersey.core</groupId>