You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by km...@apache.org on 2013/05/16 14:13:19 UTC

git commit: KNOX-68: Add switch to setup the environment.

Updated Branches:
  refs/heads/master b395dfe3b -> 539ea2b89


KNOX-68: Add switch to setup the environment.


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

Branch: refs/heads/master
Commit: 539ea2b89effa32475a9f8ceb97b44cca2fd0f61
Parents: b395dfe
Author: Kevin Minder <ke...@hortonworks.com>
Authored: Thu May 16 08:13:17 2013 -0400
Committer: Kevin Minder <ke...@hortonworks.com>
Committed: Thu May 16 08:13:17 2013 -0400

----------------------------------------------------------------------
 gateway-release/home/bin/knox.sh |   81 +++++++++++++++++++++++++++------
 1 files changed, 67 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/539ea2b8/gateway-release/home/bin/knox.sh
----------------------------------------------------------------------
diff --git a/gateway-release/home/bin/knox.sh b/gateway-release/home/bin/knox.sh
index 0ff9066..47c2551 100644
--- a/gateway-release/home/bin/knox.sh
+++ b/gateway-release/home/bin/knox.sh
@@ -20,9 +20,12 @@
 #Knox PID
 PID=0
 
-#start, stop or status
+#start, stop, status, clean or setup
 KNOX_LAUNCH_COMMAND=$1
 
+#User Name for setup parameter
+KNOX_LAUNCH_USER=$2
+
 #start/stop script location
 KNOX_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
@@ -58,14 +61,17 @@ function main {
       clean) 
          knoxClean
          ;;
+      setup) 
+         setupEnv $KNOX_LAUNCH_USER
+         ;;
       *)
-         printf "Usage: $0 {start|stop|status|clean}\n"
+         printf "Usage: $0 {start|stop|status|clean|setup [USER_NAME]}\n"
          ;;
    esac
 }
 
 function knoxStart {
-   prepareEnv
+   createLogFiles
 
    getPID
    if [ $? -eq 0 ]; then
@@ -134,14 +140,7 @@ function knoxClean {
    getPID
    knoxIsRunning $PID
    if [ $? -eq 0 ]; then 
-     rm -f $PID_FILE
-     printf "Removed the Knox PID file: $PID_FILE.\n"
-     
-     rm -f $OUT_FILE
-     printf "Removed the Knox OUT file: $OUT_FILE.\n"
-     
-     rm -f $ERR_FILE
-     printf "Removed the Knox ERR file: $ERR_FILE.\n"
+     deleteLogFiles
      return 0
    else
      printf "Can't clean files the Knox is run with PID=$PID.\n" 
@@ -191,12 +190,66 @@ function knoxKill {
    return 1
 }
 
-function prepareEnv {
-   if [ ! -d "$PID_DIR" ]; then mkdir -p $PID_DIR; fi
-   if [ ! -d "$LOG_DIR" ]; then mkdir -p $LOG_DIR; fi
+function createLogFiles {
    if [ ! -f "$OUT_FILE" ]; then touch $OUT_FILE; fi
    if [ ! -f "$ERR_FILE" ]; then touch $ERR_FILE; fi   
 }
 
+function deleteLogFiles {
+     rm -f $PID_FILE
+     printf "Removed the Knox PID file: $PID_FILE.\n"
+     
+     rm -f $OUT_FILE
+     printf "Removed the Knox OUT file: $OUT_FILE.\n"
+     
+     rm -f $ERR_FILE
+     printf "Removed the Knox ERR file: $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"
+      return 1
+   fi
+
+   chown -f $userName $dirName
+   if [ $? -ne 0 ]; then
+      printf "Can't change owner of \"$dirName\" folder to \"$userName\" user.\n" 
+      return 1
+   fi
+
+   chmod o=rwx $dirName 
+   if [ $? -ne 0 ]; then
+      printf "Can't grant rwx permission to \"$userName\" user on \"$dirName\"\n" 
+      return 1
+   fi
+
+   return 0
+}
+
+function setupEnv {
+   local userName=$1
+   
+   if [ -z $userName ]; then 
+      printf "Empty user name is not allowed. Parameters: setup [USER_NAME]\n"
+      return 1
+   fi
+
+   id -u $1 >/dev/null 2>&1
+   if [ $? -eq 1 ]; then
+      printf "\"$userName\" is not valid user name. Parameters: setup [USER_NAME]\n"
+      return 1
+   fi
+
+   setDirPermission $PID_DIR $userName
+   setDirPermission $LOG_DIR $userName
+
+   java -jar $KNOX_JAR -persist-master 
+}
+
 #Starting main
 main $KNOX_LAUNCH_COMMAND