knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject git commit: KNOX-206: User should be able to run gateway.sh script under its own but not root account
Date Thu, 16 Jan 2014 22:46:32 GMT
Updated Branches:
  refs/heads/master 6aaa7021a -> 4f5bf9bb5


KNOX-206: User should be able to run gateway.sh script under its own but not root account


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

Branch: refs/heads/master
Commit: 4f5bf9bb5b55740c3e9bde50dda71d51abda6b0a
Parents: 6aaa702
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Thu Jan 16 17:37:48 2014 -0500
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Thu Jan 16 17:37:48 2014 -0500

----------------------------------------------------------------------
 build.xml                                       |  58 ++--
 gateway-release/home/bin/gateway.sh             | 207 ++++++++------
 gateway-release/home/bin/ldap.sh                | 283 +++++++++++++++++++
 .../home/conf/gateway-log4j.properties          |  41 +++
 gateway-release/home/conf/ldap-log4j.properties |  32 +++
 gateway-release/home/conf/log4j.properties      |  31 --
 gateway-release/src/assembly.xml                |  12 +
 .../src/main/resources/META-INF/launcher.cfg    |   2 +
 .../apache/hadoop/gateway/GatewayServer.java    |  33 +--
 .../src/main/resources/META-INF/launcher.cfg    |   1 +
 .../ldap/SimpleLdapDirectoryServer.java         |  15 +-
 .../hadoop/gateway/GatewayFuncTestDriver.java   |   5 +-
 .../GatewayLdapDynamicGroupFuncTest.java        |   5 +-
 .../gateway/GatewayLdapGroupFuncTest.java       |   5 +-
 .../gateway/GatewayLocalServiceFuncTest.java    |   7 +-
 .../hadoop/gateway/GatewaySampleFuncTest.java   |   5 +-
 .../hadoop/gateway/GatewayTestConfig.java       |  10 +-
 .../src/test/resources/log4j.properties         |   2 +-
 .../apache/hadoop/gateway/launcher/Invoker.java |  27 +-
 .../hadoop/gateway/launcher/Launcher.java       |   2 +
 pom.xml                                         |  14 +-
 21 files changed, 621 insertions(+), 176 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index 71ca155..9af59ed 100644
--- a/build.xml
+++ b/build.xml
@@ -41,6 +41,10 @@
         <os family="unix"/>
     </condition>
 
+    <condition property="isWindows">
+        <os family="windows"/>
+    </condition>
+
     <condition property="mvn.cmd" value="mvn">
         <os family="unix" />
     </condition>
@@ -294,38 +298,60 @@
         </exec>
     </target>
 
-    <target name="install-test-home" description="Install binary release into install directory.">
+    <target name="delete-test-home" depends="_init">
         <delete dir="${install.dir}" quiet="true"/>
-        <unzip src="target/${gateway-version}/${gateway-artifact}-${gateway-version}.zip/" dest="${install.dir}"/>
+    </target>
+
+    <target name="_install-test-home-windows" depends="delete-test-home" if="isWindows">
+        <unzip src="target/${gateway-version}/${gateway-artifact}-${gateway-version}.zip" dest="${install.dir}"/>
+    </target>
+
+    <target name="_install-test-home-unix" depends="delete-test-home" if="isUnix">
+        <untar src="target/${gateway-version}/${gateway-artifact}-${gateway-version}.tar.gz" dest="${install.dir}" compression="gzip"/>
+        <chmod file="${install.dir}/${gateway-artifact}-${gateway-version}/bin/gateway.sh" perm="544"/>
+        <chmod file="${install.dir}/${gateway-artifact}-${gateway-version}/bin/ldap.sh" perm="544"/>
+    </target>
+
+    <target name="install-test-home" depends="_install-test-home-unix,_install-test-home-windows" description="Install binary release into install directory.">
         <echo file="${install.dir}/${gateway-artifact}-${gateway-version}/data/security/master">#1.0# Mon, Aug 26 2013 14:25:31.483
-cGkvajhUZHBNSTQ9OjpPMk5PQktYaHRyUmJoTW1zWGo0bytRPT06OkxtVjlvSDdIOWdvSEZqNTRlWVJ2N3c9PQ==</echo>
+            cGkvajhUZHBNSTQ9OjpPMk5PQktYaHRyUmJoTW1zWGo0bytRPT06OkxtVjlvSDdIOWdvSEZqNTRlWVJ2N3c9PQ==</echo>
         <chmod file="${install.dir}/${gateway-artifact}-${gateway-version}/data/security/master" perm="600"/>
     </target>
 
-    <target name="spawn-test-ldap" description="Spawn test LDAP server.">
-        <exec executable="java" dir="${install.dir}/${gateway-artifact}-${gateway-version}" spawn="true">
-            <arg value="-jar"/>
-            <arg value="bin/ldap.jar"/>
-            <arg value="conf"/>
+    <target name="start-test-ldap" description="Spawn test LDAP server.">
+        <exec executable="bin/ldap.sh" dir="${install.dir}/${gateway-artifact}-${gateway-version}">
+            <arg value="start"/>
         </exec>
     </target>
 
-    <target name="start-test-ldap" description="Spawn test LDAP server.">
-        <exec executable="java" dir="${install.dir}/${gateway-artifact}-${gateway-version}">
-            <arg value="-jar"/>
-            <arg value="bin/ldap.jar"/>
-            <arg value="conf"/>
+    <target name="start-test-gateway" description="Start test gateway server.">
+        <exec executable="bin/gateway.sh" dir="${install.dir}/${gateway-artifact}-${gateway-version}">
+            <arg value="start"/>
         </exec>
     </target>
 
-    <target name="start-test-gateway" description="Start test gateway server.">
+    <target name="start-debug-gateway" description="Start test gateway server.">
         <exec executable="java" dir="${install.dir}/${gateway-artifact}-${gateway-version}">
-            <arg value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"/>
+            <arg value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"/>
             <arg value="-jar"/>
             <arg value="bin/gateway.jar"/>
         </exec>
     </target>
 
-    <target name="start-test-servers" depends="spawn-test-ldap,start-test-gateway" description="Spawn test LDAP server and start test gateway server."/>
+    <target name="stop-test-ldap" description="Spawn test LDAP server.">
+        <exec executable="bin/ldap.sh" dir="${install.dir}/${gateway-artifact}-${gateway-version}">
+            <arg value="stop"/>
+        </exec>
+    </target>
+
+    <target name="stop-test-gateway" description="Start test gateway server.">
+        <exec executable="bin/gateway.sh" dir="${install.dir}/${gateway-artifact}-${gateway-version}">
+            <arg value="stop"/>
+        </exec>
+    </target>
+
+    <target name="start-test-servers" depends="start-test-ldap,start-test-gateway" description="Start test LDAP and test gateway servers."/>
+    <target name="stop-test-servers" depends="stop-test-gateway,stop-test-ldap" description="Stop test LDAP server and gateway servers."/>
+    <target name="restart-test-servers" depends="stop-test-servers,start-test-servers" description="Restart test LDAP and gateway servers."/>
 
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-release/home/bin/gateway.sh
----------------------------------------------------------------------
diff --git a/gateway-release/home/bin/gateway.sh b/gateway-release/home/bin/gateway.sh
index 2812a80..ae7d388 100755
--- a/gateway-release/home/bin/gateway.sh
+++ b/gateway-release/home/bin/gateway.sh
@@ -17,55 +17,78 @@
 #  limitations under the License.
 #
 
-#Knox PID
-PID=0
+# The app's label
+APP_LABEL=Gateway
 
-# Start, stop, status, clean or setup
-KNOX_LAUNCH_COMMAND=$1
+# The app's name
+APP_NAME=gateway
 
-# User Name for setup parameter
-KNOX_LAUNCH_USER=$2
+# Start/stop script location
+APP_BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# The app's jar name
+APP_JAR="$APP_BIN_DIR/gateway.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"
 
-# start/stop script location
-KNOX_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+# The app's logging options
+APP_LOG_OPTS=""
 
-# GATEWAY_HOME
-KNOX_HOME=`dirname $KNOX_SCRIPT_DIR`
+# The app's memory options
+APP_MEM_OPTS=""
 
-#App name
-KNOX_NAME=knox
+# The app's debugging options
+APP_DBG_OPTS=""
+
+# The app's PID
+APP_PID=0
+
+# Start, stop, status, clean or setup
+APP_LAUNCH_CMD=$1
+
+# User Name for setup parameter
+APP_LAUNCH_USER=$2
 
-#The Knox's jar name
-KNOX_JAR="$KNOX_SCRIPT_DIR/gateway.jar"
+# Name of PID file
+APP_PID_DIR="$APP_HOME_DIR/pids"
+APP_PID_FILE="$APP_PID_DIR/$APP_NAME.pid"
 
-#Name of PID file
-PID_DIR="/var/run/$KNOX_NAME"
-PID_FILE="$PID_DIR/$KNOX_NAME.pid"
+# Name of LOG/OUT/ERR file
+APP_OUT_FILE="$APP_LOG_DIR/$APP_NAME.out"
+APP_ERR_FILE="$APP_LOG_DIR/$APP_NAME.err"
 
-#Name of LOG/OUT/ERR file
-LOG_DIR="/var/log/$KNOX_NAME"
-OUT_FILE="$LOG_DIR/$KNOX_NAME.out"
-ERR_FILE="$LOG_DIR/$KNOX_NAME.err"
+# Java command
+JAVA_CMD=java
 
-#The max time to wait
-MAX_WAIT_TIME=10
+# The start wait time
+APP_START_WAIT_TIME=2
+
+# The kill wait time limit
+APP_KILL_WAIT_TIME=10
 
 function main {
    case "$1" in
       start)  
-         knoxStart
+         appStart
          ;;
       stop)   
-         knoxStop
+         appStop
          ;;
       status) 
-         knoxStatus
+         appStatus
          ;;
       clean) 
-         knoxClean
+         appClean
          ;;
       setup) 
-         setupEnv $KNOX_LAUNCH_USER
+         setupEnv $APP_LAUNCH_USER
          ;;
       help)
          printHelp
@@ -76,64 +99,70 @@ function main {
    esac
 }
 
-function knoxStart {
+function appStart {
    createLogFiles
 
    getPID
    if [ $? -eq 0 ]; then
-     printf "Knox is already running with PID=$PID.\n"
+     printf "$APP_LABEL is already running with PID $APP_PID.\n"
      exit 0
    fi
   
-   printf "Starting Knox "
+   printf "Starting $APP_LABEL "
    
-   rm -f $PID_FILE
+   rm -f $APP_PID_FILE
 
-   nohup java -DGATEWAY_HOME=$KNOX_HOME -jar $KNOX_JAR >>$OUT_FILE 2>>$ERR_FILE & printf $!>$PID_FILE || exit 1
+   nohup $JAVA_CMD $APP_MEM_OPTS $APP_DBC_OPTS $APP_LOG_OPTS -jar $APP_JAR >>$APP_OUT_FILE 2>>$APP_ERR_FILE & printf $!>$APP_PID_FILE || exit 1
 
    getPID
-   knoxIsRunning $PID
+   for ((i=0; i<APP_START_WAIT_TIME*10; i++)); do
+      appIsRunning $APP_PID
+      if [ $? -eq 0 ]; then break; fi
+      sleep 0.1
+   done
+   appIsRunning $APP_PID
    if [ $? -ne 1 ]; then
       printf "failed.\n"
+      rm -f $APP_PID_FILE
       exit 1
    fi
-
-   printf "succeeded with PID=$PID.\n"
+   printf "succeeded with PID $APP_PID.\n"
    return 0
 }
 
-function knoxStop {
+function appStop {
    getPID
-   knoxIsRunning $PID
+   appIsRunning $APP_PID
    if [ $? -eq 0 ]; then
-     printf "Knox is not running.\n"
+     printf "$APP_LABEL is not running.\n"
+     rm -f $APP_PID_FILE
      return 0
    fi
   
-   printf "Stopping Knox [$PID] "
-   knoxKill $PID >>$OUT_FILE 2>>$ERR_FILE 
+   printf "Stopping $APP_LABEL with $APP_PID "
+   appKill $APP_PID >>$APP_OUT_FILE 2>>$APP_ERR_FILE
 
    if [ $? -ne 0 ]; then 
      printf "failed. \n"
      exit 1
    else
-     rm -f $PID_FILE
+     rm -f $APP_PID_FILE
      printf "succeeded.\n"
      return 0
    fi
 }
 
-function knoxStatus {
-   printf "Knox "
+function appStatus {
+   printf "$APP_LABEL "
    getPID
    if [ $? -eq 1 ]; then
-     printf "is not running. No pid file found.\n"
+     printf "is not running. No PID file found.\n"
      return 0
    fi
 
-   knoxIsRunning $PID
+   appIsRunning $APP_PID
    if [ $? -eq 1 ]; then
-     printf "is running with PID=$PID.\n"
+     printf "is running with PID $APP_PID.\n"
      exit 1
    else
      printf "is not running.\n"
@@ -141,35 +170,54 @@ function knoxStatus {
    fi
 }
 
-# Removed the Knox PID file if Knox is not run
-function knoxClean {
+# Removed the app PID file if app is not run
+function appClean {
    getPID
-   knoxIsRunning $PID
+   appIsRunning $APP_PID
    if [ $? -eq 0 ]; then 
      deleteLogFiles
      return 0
    else
-     printf "Can't clean files.  Knox is running with PID=$PID.\n"
+     printf "Can't clean files.  $APP_LABEL is running with PID $APP_PID.\n"
      exit 1
    fi
 }
 
-# Returns 0 if the Knox is running and sets the $PID variable.
+function appKill {
+   local localPID=$1
+   kill $localPID || return 1
+   for ((i=0; i<APP_KILL_WAIT_TIME*10; i++)); do
+      appIsRunning $localPID
+      if [ $? -eq 0 ]; then return 0; fi
+      sleep 0.1
+   done
+
+   kill -s KILL $localPID || return 1
+   for ((i=0; i<APP_KILL_WAIT_TIME*10; i++)); do
+      appIsRunning $localPID
+      if [ $? -eq 0 ]; then return 0; fi
+      sleep 0.1
+   done
+
+   return 1
+}
+
+# Returns 0 if the app is running and sets the $PID variable.
 function getPID {
-   if [ ! -d $PID_DIR ]; then
-      printf "Can't find pid dir.  Run sudo $0 setup.\n"
+   if [ ! -d $APP_PID_DIR ]; then
+      printf "Can't find PID dir.  Run sudo $0 setup.\n"
       exit 1
    fi
-   if [ ! -f $PID_FILE ]; then
-     PID=0
+   if [ ! -f $APP_PID_FILE ]; then
+     APP_PID=0
      return 1
    fi
    
-   PID="$(<$PID_FILE)"
+   APP_PID="$(<$APP_PID_FILE)"
    return 0
 }
 
-function knoxIsRunning {
+function appIsRunning {
    if [ $1 -eq 0 ]; then return 0; fi
 
    ps -p $1 > /dev/null
@@ -181,43 +229,24 @@ function knoxIsRunning {
    fi
 }
 
-function knoxKill {
-   local localPID=$1
-   kill $localPID || return 1
-   for ((i=0; i<MAX_WAIT_TIME*10; i++)); do
-      knoxIsRunning $localPID
-      if [ $? -eq 0 ]; then return 0; fi
-      sleep 0.1
-   done   
-
-   kill -s KILL $localPID || return 1
-   for ((i=0; i<MAX_WAIT_TIME*10; i++)); do
-      knoxIsRunning $localPID
-      if [ $? -eq 0 ]; then return 0; fi
-      sleep 0.1
-   done
-
-   return 1
-}
-
 function createLogFiles {
-   if [ ! -d "$LOG_DIR" ]; then
+   if [ ! -d "$APP_LOG_DIR" ]; then
       printf "Can't find log dir.  Run sudo $0 setup.\n"
       exit 1
    fi
-   if [ ! -f "$OUT_FILE" ]; then touch $OUT_FILE; fi
-   if [ ! -f "$ERR_FILE" ]; then touch $ERR_FILE; fi   
+   if [ ! -f "$APP_OUT_FILE" ]; then touch $APP_OUT_FILE; fi
+   if [ ! -f "$APP_ERR_FILE" ]; then touch $APP_ERR_FILE; fi   
 }
 
 function deleteLogFiles {
-     rm -f $PID_FILE
-     printf "Removed the Knox PID file: $PID_FILE.\n"
+     rm -f $APP_PID_FILE
+     printf "Removed the $APP_LABEL PID file: $APP_PID_FILE.\n"
      
-     rm -f $OUT_FILE
-     printf "Removed the Knox OUT file: $OUT_FILE.\n"
+     rm -f $APP_OUT_FILE
+     printf "Removed the $APP_LABEL OUT file: $APP_OUT_FILE.\n"
      
-     rm -f $ERR_FILE
-     printf "Removed the Knox ERR file: $ERR_FILE.\n"  
+     rm -f $APP_ERR_FILE
+     printf "Removed the $APP_LABEL ERR file: $APP_ERR_FILE.\n"
 }
 
 function setDirPermission {
@@ -258,15 +287,15 @@ function setupEnv {
       exit 1
    fi
 
-   java -DGATEWAY_HOME=$KNOX_HOME -jar $KNOX_JAR -persist-master -nostart
+   $JAVA_CMD -jar $APP_JAR -persist-master -nostart
 
    return 0
 }
 
 function printHelp {
-   java -jar $KNOX_JAR -help
+   $JAVA_CMD -jar $APP_JAR -help
    return 0
 }
 
 #Starting main
-main $KNOX_LAUNCH_COMMAND
+main $APP_LAUNCH_CMD

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-release/home/bin/ldap.sh
----------------------------------------------------------------------
diff --git a/gateway-release/home/bin/ldap.sh b/gateway-release/home/bin/ldap.sh
new file mode 100755
index 0000000..fc2cef3
--- /dev/null
+++ b/gateway-release/home/bin/ldap.sh
@@ -0,0 +1,283 @@
+#!/bin/sh
+
+#
+#  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.
+#
+
+# App name
+APP_LABEL=LDAP
+
+# App 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/$APP_JAR_NAME"
+
+# 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 log dir
+APP_LOG_DIR="$APP_HOME_DIR/logs"
+
+# The app's Log4j options
+APP_LOG_OPTS=""
+
+# The app's memory options
+APP_MEM_OPTS=""
+
+# The app's debugging options
+APP_DBG_OPTS=""
+
+# Start, stop, status, clean or setup
+APP_LAUNCH_COMMAND=$1
+
+# User Name for setup parameter
+APP_LAUNCH_USER=$2
+
+# The app's PID
+APP_PID=0
+
+# The name of the PID file
+APP_PID_DIR="$APP_HOME_DIR/pids"
+APP_PID_FILE="$APP_PID_DIR/$APP_NAME.pid"
+
+#Name of LOG/OUT/ERR file
+APP_OUT_FILE="$APP_LOG_DIR/$APP_NAME.out"
+APP_ERR_FILE="$APP_LOG_DIR/$APP_NAME.err"
+
+# Java command
+JAVA_CMD=java
+
+# The start wait time
+APP_START_WAIT_TIME=2
+
+# The kill wait time limit
+APP_KILL_WAIT_TIME=10
+
+function main {
+   case "$1" in
+      start)  
+         appStart
+         ;;
+      stop)   
+         appStop
+         ;;
+      status) 
+         appStatus
+         ;;
+      clean) 
+         appClean
+         ;;
+      setup) 
+         setupEnv $APP_LAUNCH_USER
+         ;;
+      *)
+         printHelp
+         ;;
+   esac
+}
+
+function appStart {
+   createLogFiles
+
+   getPID
+   if [ $? -eq 0 ]; then
+     printf "$APP_LABEL is already running with PID $APP_PID.\n"
+     exit 0
+   fi
+  
+   printf "Starting $APP_LABEL "
+   
+   rm -f $APP_PID_FILE
+
+   nohup $JAVA_CMD $APP_MEM_OPTS $APP_DBG_OPTS $APP_LOG_OPTS -jar $APP_JAR $APP_CONF_DIR >>$APP_OUT_FILE 2>>$APP_ERR_FILE & printf $!>$APP_PID_FILE || exit 1
+
+   getPID
+   for ((i=0; i<APP_START_WAIT_TIME*10; i++)); do
+      appIsRunning $APP_PID
+      if [ $? -eq 0 ]; then break; fi
+      sleep 0.1
+   done
+   appIsRunning $APP_PID
+   if [ $? -ne 1 ]; then
+      printf "failed.\n"
+      rm -f $APP_PID_FILE
+      exit 1
+   fi
+   printf "succeeded with PID $APP_PID.\n"
+   return 0
+}
+
+function appStop {
+   getPID
+   appIsRunning $APP_PID
+   if [ $? -eq 0 ]; then
+     printf "$APP_LABEL is not running.\n"
+     rm -f $APP_PID_FILE
+     return 0
+   fi
+  
+   printf "Stopping $APP_LABEL with PID $APP_PID "
+   appKill $APP_PID >>$APP_OUT_FILE 2>>$APP_ERR_FILE
+
+   if [ $? -ne 0 ]; then 
+     printf "failed. \n"
+     exit 1
+   else
+     rm -f $APP_PID_FILE
+     printf "succeeded.\n"
+     return 0
+   fi
+}
+
+function appStatus {
+   printf "$APP_LABEL "
+   getPID
+   if [ $? -eq 1 ]; then
+     printf "is not running. No PID file found.\n"
+     return 0
+   fi
+
+   appIsRunning $APP_PID
+   if [ $? -eq 1 ]; then
+     printf "is running with PID $APP_PID.\n"
+     exit 1
+   else
+     printf "is not running.\n"
+     return 0
+   fi
+}
+
+# Removed the PID file if app is not run
+function appClean {
+   getPID
+   appIsRunning $APP_PID
+   if [ $? -eq 0 ]; then 
+     deleteLogFiles
+     return 0
+   else
+     printf "Can't clean files.  $APP_LABEL is running with PID $APP_PID.\n"
+     exit 1
+   fi
+}
+
+function appKill {
+   local localPID=$1
+   kill $localPID || return 1
+   for ((i=0; i<APP_KILL_WAIT_TIME*10; i++)); do
+      appIsRunning $localPID
+      if [ $? -eq 0 ]; then return 0; fi
+      sleep 0.1
+   done
+
+   kill -s KILL $localPID || return 1
+   for ((i=0; i<APP_KILL_WAIT_TIME*10; i++)); do
+      appIsRunning $localPID
+      if [ $? -eq 0 ]; then return 0; fi
+      sleep 0.1
+   done
+
+   return 1
+}
+
+# Returns 0 if the app is running and sets the $APP_PID variable.
+function getPID {
+   if [ ! -d $APP_PID_DIR ]; then
+      printf "Can't find pid dir.  Run sudo $0 setup.\n"
+      exit 1
+   fi
+   if [ ! -f $APP_PID_FILE ]; then
+     APP_PID=0
+     return 1
+   fi
+   
+   APP_PID="$(<$APP_PID_FILE)"
+   return 0
+}
+
+function appIsRunning {
+   if [ $1 -eq 0 ]; then return 0; fi
+
+   ps -p $1 > /dev/null
+
+   if [ $? -eq 1 ]; then
+     return 0
+   else
+     return 1
+   fi
+}
+
+function createLogFiles {
+   if [ ! -d "$APP_LOG_DIR" ]; then
+      printf "Can't find log dir.  Run sudo $0 setup.\n"
+      exit 1
+   fi
+   if [ ! -f "$APP_OUT_FILE" ]; then touch $APP_OUT_FILE; fi
+   if [ ! -f "$APP_ERR_FILE" ]; then touch $APP_ERR_FILE; fi   
+}
+
+function deleteLogFiles {
+     rm -f $APP_PID_FILE
+     printf "Removed the $APP_LABEL PID file: $APP_PID_FILE.\n"
+     
+     rm -f $APP_OUT_FILE
+     printf "Removed the $APP_LABEL OUT file: $APP_OUT_FILE.\n"
+     
+     rm -f $APP_ERR_FILE
+     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.  Run sudo $0 setup.\n"
+      exit 1
+   fi
+
+   chown -f $userName $dirName
+   if [ $? -ne 0 ]; then
+      printf "Can't change owner of \"$dirName\" folder to \"$userName\" user.  Run command with sudo.\n"
+      exit 1
+   fi
+
+   chmod o=rwx $dirName 
+   if [ $? -ne 0 ]; then
+      printf "Can't grant rwx permission to \"$userName\" user on \"$dirName\".  Run command with sudo.\n"
+      exit 1
+   fi
+
+   return 0
+}
+
+function printHelp {
+   printf "Usage: $0 {start|stop|status|clean}\n"
+   return 0
+}
+
+# Starting main
+main $APP_LAUNCH_COMMAND

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-release/home/conf/gateway-log4j.properties
----------------------------------------------------------------------
diff --git a/gateway-release/home/conf/gateway-log4j.properties b/gateway-release/home/conf/gateway-log4j.properties
new file mode 100644
index 0000000..5844f2c
--- /dev/null
+++ b/gateway-release/home/conf/gateway-log4j.properties
@@ -0,0 +1,41 @@
+# 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.
+
+app.log.dir=${launcher.dir}/../logs
+app.log.file=${launcher.name}.log
+
+log4j.rootLogger=ERROR, drfa
+
+log4j.logger.org.apache.hadoop.gateway=INFO
+#log4j.logger.org.apache.hadoop.gateway=DEBUG
+
+#log4j.logger.org.eclipse.jetty=DEBUG
+#log4j.logger.org.apache.shiro=DEBUG
+#log4j.logger.org.apache.http=DEBUG
+#log4j.logger.org.apache.http.client=DEBUG
+#log4j.logger.org.apache.http.headers=DEBUG
+#log4j.logger.org.apache.http.wire=DEBUG
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
+
+log4j.appender.drfa=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.drfa.File=${app.log.dir}/${app.log.file}
+log4j.appender.drfa.DatePattern=.yyyy-MM-dd
+log4j.appender.drfa.layout=org.apache.log4j.PatternLayout
+log4j.appender.drfa.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
+

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-release/home/conf/ldap-log4j.properties
----------------------------------------------------------------------
diff --git a/gateway-release/home/conf/ldap-log4j.properties b/gateway-release/home/conf/ldap-log4j.properties
new file mode 100644
index 0000000..fabb47f
--- /dev/null
+++ b/gateway-release/home/conf/ldap-log4j.properties
@@ -0,0 +1,32 @@
+# 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.
+
+app.log.dir=${launcher.dir}/../logs
+app.log.file=${launcher.name}.log
+
+log4j.rootLogger=ERROR, drfa
+log4j.logger.org.apache.directory.server.ldap.LdapServer=INFO
+log4j.logger.org.apache.directory=WARN
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
+
+log4j.appender.drfa=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.drfa.File=${app.log.dir}/${app.log.file}
+log4j.appender.drfa.DatePattern=.yyyy-MM-dd
+log4j.appender.drfa.layout=org.apache.log4j.PatternLayout
+log4j.appender.drfa.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-release/home/conf/log4j.properties
----------------------------------------------------------------------
diff --git a/gateway-release/home/conf/log4j.properties b/gateway-release/home/conf/log4j.properties
deleted file mode 100644
index c56333e..0000000
--- a/gateway-release/home/conf/log4j.properties
+++ /dev/null
@@ -1,31 +0,0 @@
-# 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.
-
-log4j.rootLogger=ERROR, stdout
-
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
-
-log4j.logger.org.apache.hadoop.gateway=INFO
-#log4j.logger.org.apache.hadoop.gateway=DEBUG
-
-#log4j.logger.org.eclipse.jetty=ERROR
-#log4j.logger.org.apache.shiro=DEBUG
-#log4j.logger.org.apache.http=DEBUG
-#log4j.logger.org.apache.http.client=DEBUG
-#log4j.logger.org.apache.http.headers=DEBUG
-#log4j.logger.org.apache.http.wire=DEBUG

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-release/src/assembly.xml
----------------------------------------------------------------------
diff --git a/gateway-release/src/assembly.xml b/gateway-release/src/assembly.xml
index 196ef1b..b2ec99b 100644
--- a/gateway-release/src/assembly.xml
+++ b/gateway-release/src/assembly.xml
@@ -29,11 +29,22 @@
                 <include>**</include>
             </includes>
             <excludes>
+                <exclude>**/*.sh</exclude>
                 <exclude>**/.idea/**</exclude>
                 <exclude>**/*.iml</exclude>
                 <exclude>**/.project</exclude>
                 <exclude>**/.settings/**</exclude>
             </excludes>
+            <fileMode>0644</fileMode>
+            <directoryMode>0744</directoryMode>
+        </fileSet>
+        <fileSet>
+            <directory>home</directory>
+            <outputDirectory></outputDirectory>
+            <includes>
+                <include>**/*.sh</include>
+            </includes>
+            <fileMode>0755</fileMode>
         </fileSet>
         <fileSet>
             <directory>..</directory>
@@ -46,6 +57,7 @@
                 <include>NOTICE</include>
                 <include>README</include>
             </includes>
+            <fileMode>0444</fileMode>
         </fileSet>
     </fileSets>
     <dependencySets>

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-server-launcher/src/main/resources/META-INF/launcher.cfg
----------------------------------------------------------------------
diff --git a/gateway-server-launcher/src/main/resources/META-INF/launcher.cfg b/gateway-server-launcher/src/main/resources/META-INF/launcher.cfg
index b69058a..e0ac429 100644
--- a/gateway-server-launcher/src/main/resources/META-INF/launcher.cfg
+++ b/gateway-server-launcher/src/main/resources/META-INF/launcher.cfg
@@ -14,3 +14,5 @@
 # limitations under the License.
 main.class = org.apache.hadoop.gateway.GatewayServer
 class.path = ../lib/*.jar;../dep/*.jar;../ext;../ext/*.jar
+GATEWAY_HOME=${launcher.dir}/..
+log4j.configuration=${GATEWAY_HOME}/conf/${launcher.name}-log4j.properties
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
index 0527efc..794a50f 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
@@ -77,6 +77,7 @@ public class GatewayServer {
 
   public static void main( String[] args ) {
     try {
+      configureLogging();
       CommandLine cmd = GatewayCommandLine.parse( args );
       if( cmd.hasOption( GatewayCommandLine.HELP_LONG ) ) {
         GatewayCommandLine.printHelp();
@@ -91,7 +92,6 @@ public class GatewayServer {
           log.failedToInstantiateGatewayServices();
         }
         GatewayConfig config = new GatewayConfigImpl();
-        configureLogging( config );
         if (config.isHadoopKerberosSecured()) {
           configureKerberosSecurity( config );
         }
@@ -122,21 +122,22 @@ public class GatewayServer {
     return services;
   }
 
-  private static void configureLogging( GatewayConfig config ) {
-    String fileName = config.getGatewayConfDir() + File.separator + "log4j.properties";
-    File file = new File( fileName );
-    if( file.isFile() && file.canRead() ) {
-      FileInputStream stream;
-      try {
-        stream = new FileInputStream( file );
-        Properties properties = new Properties();
-        properties.load( stream );
-        PropertyConfigurator.configure( properties );
-        log.loadedLoggingConfig( fileName );
-      } catch( IOException e ) {
-        log.failedToLoadLoggingConfig( fileName );
-      }
-    }
+  private static void configureLogging() {
+    PropertyConfigurator.configure( System.getProperty( "log4j.configuration" ) );
+//    String fileName = config.getGatewayConfDir() + File.separator + "log4j.properties";
+//    File file = new File( fileName );
+//    if( file.isFile() && file.canRead() ) {
+//      FileInputStream stream;
+//      try {
+//        stream = new FileInputStream( file );
+//        Properties properties = new Properties();
+//        properties.load( stream );
+//        PropertyConfigurator.configure( properties );
+//        log.loadedLoggingConfig( fileName );
+//      } catch( IOException e ) {
+//        log.failedToLoadLoggingConfig( fileName );
+//      }
+//    }
   }
 
   private static void configureKerberosSecurity( GatewayConfig config ) {

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-test-ldap-launcher/src/main/resources/META-INF/launcher.cfg
----------------------------------------------------------------------
diff --git a/gateway-test-ldap-launcher/src/main/resources/META-INF/launcher.cfg b/gateway-test-ldap-launcher/src/main/resources/META-INF/launcher.cfg
index c71dc53..dda1a25 100644
--- a/gateway-test-ldap-launcher/src/main/resources/META-INF/launcher.cfg
+++ b/gateway-test-ldap-launcher/src/main/resources/META-INF/launcher.cfg
@@ -14,3 +14,4 @@
 # limitations under the License.
 main.class = org.apache.hadoop.gateway.security.ldap.SimpleLdapDirectoryServer
 class.path = ../lib/*.jar;../dep/*.jar
+log4j.configuration=${launcher.dir}/../conf/${launcher.name}-log4j.properties
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-test-ldap/src/main/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapDirectoryServer.java
----------------------------------------------------------------------
diff --git a/gateway-test-ldap/src/main/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapDirectoryServer.java b/gateway-test-ldap/src/main/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapDirectoryServer.java
index 96e3914..139b83b 100644
--- a/gateway-test-ldap/src/main/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapDirectoryServer.java
+++ b/gateway-test-ldap/src/main/java/org/apache/hadoop/gateway/security/ldap/SimpleLdapDirectoryServer.java
@@ -26,9 +26,11 @@ import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.directory.server.protocol.shared.transport.Transport;
+import org.apache.log4j.PropertyConfigurator;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.net.ServerSocket;
 import java.util.UUID;
 
 public class SimpleLdapDirectoryServer {
@@ -75,6 +77,8 @@ public class SimpleLdapDirectoryServer {
   }
 
   public static void main( String[] args ) throws Exception {
+    PropertyConfigurator.configure( System.getProperty( "log4j.configuration" ) );
+
     SimpleLdapDirectoryServer ldap;
 
     File file;
@@ -87,10 +91,19 @@ public class SimpleLdapDirectoryServer {
       }
       file = new File( dir, "users.ldif" );
     }
+
     if( !file.exists() || !file.canRead() ) {
       throw new FileNotFoundException( file.getAbsolutePath() );
     }
-    ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", file, new TcpTransport( 33389 ) );
+
+    int port = 33389;
+
+    // Make sure the port is free.
+    ServerSocket socket = new ServerSocket( port );
+    socket.close();
+
+    TcpTransport transport = new TcpTransport( port );
+    ldap = new SimpleLdapDirectoryServer( "dc=hadoop,dc=apache,dc=org", file, transport );
     ldap.start();
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
index 2b6e257..842e55a 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
@@ -135,10 +135,13 @@ public class GatewayFuncTestDriver {
 
     config.setGatewayHomeDir( gatewayDir.getAbsolutePath() );
 
+    File topoDir = new File( config.getGatewayTopologyDir() );
+    topoDir.mkdirs();
+
     File deployDir = new File( config.getGatewayDeploymentDir() );
     deployDir.mkdirs();
 
-    File descriptor = new File( deployDir, cluster + ".xml" );
+    File descriptor = new File( topoDir, cluster + ".xml" );
     FileOutputStream stream = new FileOutputStream( descriptor );
     topology.toStream( stream );
     stream.close();

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
index e64bc22..b4f0dc4 100755
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapDynamicGroupFuncTest.java
@@ -106,10 +106,13 @@ public class GatewayLdapDynamicGroupFuncTest {
     config = testConfig;
     testConfig.setGatewayHomeDir( gatewayDir.getAbsolutePath() );
 
+    File topoDir = new File( testConfig.getGatewayTopologyDir() );
+    topoDir.mkdirs();
+
     File deployDir = new File( testConfig.getGatewayDeploymentDir() );
     deployDir.mkdirs();
 
-    File descriptor = new File( deployDir, "test-cluster.xml" );
+    File descriptor = new File( topoDir, "test-cluster.xml" );
     FileOutputStream stream = new FileOutputStream( descriptor );
     createTopology(ldapPort).toStream( stream );
     stream.close();

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
index e656314..98a5c12 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLdapGroupFuncTest.java
@@ -106,10 +106,13 @@ public class GatewayLdapGroupFuncTest {
     config = testConfig;
     testConfig.setGatewayHomeDir( gatewayDir.getAbsolutePath() );
 
+    File topoDir = new File( testConfig.getGatewayTopologyDir() );
+    topoDir.mkdirs();
+
     File deployDir = new File( testConfig.getGatewayDeploymentDir() );
     deployDir.mkdirs();
 
-    File descriptor = new File( deployDir, "test-cluster.xml" );
+    File descriptor = new File( topoDir, "test-cluster.xml" );
     FileOutputStream stream = new FileOutputStream( descriptor );
     createTopology(ldapPort).toStream( stream );
     stream.close();

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java
index 0603286..6ff33da 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayLocalServiceFuncTest.java
@@ -100,10 +100,13 @@ public class GatewayLocalServiceFuncTest {
     config = testConfig;
     testConfig.setGatewayHomeDir( gatewayDir.getAbsolutePath() );
 
-    File deployDir = new File( config.getGatewayDeploymentDir() );
+    File topoDir = new File( testConfig.getGatewayTopologyDir() );
+    topoDir.mkdirs();
+
+    File deployDir = new File( testConfig.getGatewayDeploymentDir() );
     deployDir.mkdirs();
 
-    File descriptor = new File( deployDir, "cluster.xml" );
+    File descriptor = new File( topoDir, "cluster.xml" );
     FileOutputStream stream = new FileOutputStream( descriptor );
     createTopology().toStream( stream );
     stream.close();

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
index d3d962a..cfa1f32 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewaySampleFuncTest.java
@@ -98,10 +98,13 @@ public class GatewaySampleFuncTest {
     config = testConfig;
     testConfig.setGatewayHomeDir( gatewayDir.getAbsolutePath() );
 
+    File topoDir = new File( testConfig.getGatewayTopologyDir() );
+    topoDir.mkdirs();
+
     File deployDir = new File( testConfig.getGatewayDeploymentDir() );
     deployDir.mkdirs();
 
-    File descriptor = new File( deployDir, "test-cluster.xml" );
+    File descriptor = new File( topoDir, "test-cluster.xml" );
     FileOutputStream stream = new FileOutputStream( descriptor );
     createTopology().toStream( stream );
     stream.close();

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
index 90453e7..93086ad 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
@@ -29,17 +29,11 @@ public class GatewayTestConfig implements GatewayConfig {
   private String gatewayHost = "localhost";
   private int gatewayPort = 0;
   private String gatewayPath = "gateway";
-//  private String deployDir = "clusters";
   private boolean hadoopKerberosSecured = false;
   private String kerberosConfig = "/etc/knox/conf/krb5.conf";
   private boolean kerberosDebugEnabled = false;
   private String kerberosLoginConfig = "/etc/knox/conf/krb5JAASLogin.conf";
 
-//  @Override
-//  public String getGatewayHomeDir() {
-//    return gatewayHomeDir;
-//  }
-
   public void setGatewayHomeDir( String gatewayHomeDir ) {
     this.gatewayHomeDir = gatewayHomeDir;
   }
@@ -61,12 +55,12 @@ public class GatewayTestConfig implements GatewayConfig {
 
   @Override
   public String getGatewayTopologyDir() {
-    return gatewayHomeDir + "/clusters";
+    return gatewayHomeDir + "/topologies";
   }
 
   @Override
   public String getGatewayDeploymentDir() {
-    return gatewayHomeDir + "/clusters";
+    return gatewayHomeDir + "/deployments";
   }
 
 //  public void setDeploymentDir( String clusterConfDir ) {

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-test/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/resources/log4j.properties b/gateway-test/src/test/resources/log4j.properties
index 8904f59..87501a9 100644
--- a/gateway-test/src/test/resources/log4j.properties
+++ b/gateway-test/src/test/resources/log4j.properties
@@ -23,8 +23,8 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
 
-#log4j.logger.org.apache.directory=INFO
 #log4j.logger.org.apache.hadoop.gateway=DEBUG
+#log4j.logger.org.apache.directory=DEBUG
 
 #log4j.logger.org.eclipse.jetty=DEBUG
 #log4j.logger.org.apache.shiro=DEBUG

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Invoker.java
----------------------------------------------------------------------
diff --git a/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Invoker.java b/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Invoker.java
index 32fb883..472c9b2 100644
--- a/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Invoker.java
+++ b/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Invoker.java
@@ -23,6 +23,8 @@ import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.List;
 import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 class Invoker {
 
@@ -39,7 +41,11 @@ class Invoker {
 
   private static void setSysProps( Properties properties ) {
     for( String name : properties.stringPropertyNames() ) {
-      System.setProperty( name, properties.getProperty( name ) );
+      String value = System.getProperty( name, null );
+      if( value == null ) {
+        value = resolveValue( properties, name );
+        System.setProperty( name, value );
+      }
     }
   }
 
@@ -64,4 +70,23 @@ class Invoker {
     method.invoke( method.getClass(), (Object)args );
   }
 
+  private static String resolveValue( Properties properties, String name ) {
+    String value = properties.getProperty( name );
+    Pattern pattern = Pattern.compile( ".*?(\\$\\{)(.*?)(\\}).*" );
+    Matcher matcher = pattern.matcher( value );
+    while( matcher.matches() ) {
+      StringBuilder resolvedValue = new StringBuilder( value.length() );
+      resolvedValue.append( value.substring( 0, matcher.start( 1 ) ) );
+      String varName = matcher.group( 2 );
+      String varVal = properties.getProperty( varName );
+      if( varVal != null ) {
+        resolvedValue.append( varVal );
+      }
+      resolvedValue.append( value.substring( matcher.end( 3 ) ) );
+      value = resolvedValue.toString();
+      matcher = pattern.matcher( value );
+    }
+    return value;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Launcher.java
----------------------------------------------------------------------
diff --git a/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Launcher.java b/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Launcher.java
index d998ce6..20c990d 100644
--- a/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Launcher.java
+++ b/gateway-util-launcher/src/main/java/org/apache/hadoop/gateway/launcher/Launcher.java
@@ -63,6 +63,8 @@ public class Launcher {
         loadProperties( properties, externalConfigUrl );
       }
     }
+    properties.setProperty( LAUNCHER_PREFIX + "dir", launcherJarDir.getAbsolutePath() );
+    properties.setProperty( LAUNCHER_PREFIX + "name", launcherName );
     command = new Command( launcherJarDir, properties, args );
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/4f5bf9bb/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a21cdc5..b4c51f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -736,13 +736,6 @@
                 <version>2.0.0-alpha-4</version>
             </dependency>
 
-            <!--
-            <dependency>
-                <groupId>org.apache.directory.server</groupId>
-                <artifactId>apacheds-jdbm</artifactId>
-                <version>2.0.0-M5</version>
-            </dependency>
-            -->
             <dependency>
                 <groupId>org.apache.directory.server</groupId>
                 <artifactId>apacheds-all</artifactId>
@@ -757,6 +750,13 @@
             <!--
             <dependency>
                 <groupId>org.apache.directory.server</groupId>
+                <artifactId>apacheds-jdbm</artifactId>
+                <version>2.0.0-M5</version>
+            </dependency>
+            -->
+            <!--
+            <dependency>
+                <groupId>org.apache.directory.server</groupId>
                 <artifactId>apacheds-server-integ</artifactId>
                 <version>1.5.5</version>
                 <exclusions>


Mime
View raw message