KNOX-2100 - Make sure knoxshell initializes logging by using the 'launcher' framework like other products (gateway, cli, ldap) do (#181)

diff --git a/gateway-shell-release/home/bin/knoxshell.sh b/gateway-shell-release/home/bin/knoxshell.sh
index 8355ab1..52f7a98 100755
--- a/gateway-shell-release/home/bin/knoxshell.sh
+++ b/gateway-shell-release/home/bin/knoxshell.sh
@@ -64,40 +64,25 @@
     if [ -n "$APP_DBG_OPTS" ]; then
       addAppJavaOpts "${APP_DBG_OPTS}"
     fi
-
-    if [ -n "$APP_JAVA_LIB_PATH" ]; then
-      addAppJavaOpts "${APP_JAVA_LIB_PATH}"
-    fi
-
-    # echo "APP_JAVA_OPTS =" "${APP_JAVA_OPTS[@]}"
 }
 
 function main {
-   checkJava
-
-   #printf "Starting $APP_LABEL \n"
-   #printf "$@"
    case "$1" in
       init|buildTrustStore)
         if [ "$#" -ne 2 ]; then
             echo "Illegal number of parameters."
-            printHelp
-        else
-          $JAVA -cp "$APP_JAR" org.apache.knox.gateway.shell.KnoxSh "$1" --gateway "$2" || exit 1
+            printHelp && exit 1
         fi
-         ;;
-      list|destroy)
-        "$JAVA" -cp "$APP_JAR" org.apache.knox.gateway.shell.KnoxSh "$1" || exit 1
-         ;;
+        ;;
       help)
-         printHelp
-         ;;
-      *)
-         buildAppJavaOpts
-         $JAVA "${APP_JAVA_OPTS[@]}" -javaagent:"$APP_BIN_DIR"/../lib/aspectjweaver.jar -jar "$APP_JAR" "$@" || exit 1
+         printHelp && exit 0
          ;;
    esac
-   
+
+   checkJava
+   buildAppJavaOpts
+   $JAVA "${APP_JAVA_OPTS[@]}" -javaagent:"$APP_BIN_DIR"/../lib/aspectjweaver.jar -jar "$APP_JAR" "$@" || exit 1
+
    return 0
 }
 
diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java
index a674979..62079c4 100644
--- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java
+++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java
@@ -31,11 +31,14 @@
 import org.fusesource.jansi.Ansi;
 import org.fusesource.jansi.AnsiConsole;
 
-import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 public class Shell {
 
+  private static final List<String> NON_INTERACTIVE_COMMANDS = Arrays.asList("buildTrustStore", "init", "list", "destroy");
+
   private static final String[] IMPORTS = new String[] {
       KnoxSession.class.getName(),
       HBase.class.getName(),
@@ -54,10 +57,20 @@
     System.setProperty( "groovysh.prompt", "knox" );
   }
 
-  public static void main( String... args ) throws IOException {
+  public static void main( String... args ) throws Exception {
     PropertyConfigurator.configure( System.getProperty( "log4j.configuration" ) );
     if( args.length > 0 ) {
-      GroovyMain.main( args );
+      if (NON_INTERACTIVE_COMMANDS.contains(args[0])) {
+          final String[] arguments = new String[args.length == 1 ? 1:3];
+          arguments[0] = args[0];
+          if (args.length > 1) {
+            arguments[1] = "--gateway";
+            arguments[2] = args[1];
+          }
+          KnoxSh.main(arguments);
+      } else {
+          GroovyMain.main( args );
+      }
     } else {
       Groovysh shell = new Groovysh();
       for( String name : IMPORTS ) {