You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2017/03/21 03:43:19 UTC

[12/30] kylin git commit: KYLIN-2280 Port config util

KYLIN-2280 Port config util

Signed-off-by: Hongbin Ma <ma...@apache.org>


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

Branch: refs/heads/master-hbase0.98
Commit: e4ed2322b7ff37a14a0d741766304f46ea58ba69
Parents: f852863
Author: xiefan46 <95...@qq.com>
Authored: Mon Mar 13 15:41:49 2017 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Wed Mar 15 14:40:18 2017 +0800

----------------------------------------------------------------------
 build/bin/kylin.sh                   |  4 +-
 build/bin/kylin_port_replace_util.sh | 97 +++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/e4ed2322/build/bin/kylin.sh
----------------------------------------------------------------------
diff --git a/build/bin/kylin.sh b/build/bin/kylin.sh
index a87fa78..f30b751 100644
--- a/build/bin/kylin.sh
+++ b/build/bin/kylin.sh
@@ -116,7 +116,9 @@ then
     echo ""
     echo "A new Kylin instance is started by $USER. To stop it, run 'kylin.sh stop'"
     echo "Check the log at ${KYLIN_HOME}/logs/kylin.log"
-    echo "Web UI is at http://<hostname>:7070/kylin"
+    kylin_server_port=`sed -n "s/<Connector port=\"\(.*\)\" protocol=\"HTTP\/1.1\"/\1/"p ${KYLIN_HOME}/tomcat/conf/server.xml`
+    kylin_server_port=`echo ${kylin_server_port}` #ignore white space
+    echo "Web UI is at http://<hostname>:${kylin_server_port}/kylin"
     exit 0
 
 # stop command

http://git-wip-us.apache.org/repos/asf/kylin/blob/e4ed2322/build/bin/kylin_port_replace_util.sh
----------------------------------------------------------------------
diff --git a/build/bin/kylin_port_replace_util.sh b/build/bin/kylin_port_replace_util.sh
new file mode 100755
index 0000000..a51e60d
--- /dev/null
+++ b/build/bin/kylin_port_replace_util.sh
@@ -0,0 +1,97 @@
+#!/bin/bash
+#exit if find error
+# ============================================================================
+
+set -o pipefail  # trace ERR through pipes
+set -o errtrace  # trace ERR through 'time command' and other functions
+function error() {
+   SCRIPT="$0"           # script name
+   LASTLINE="$1"         # line of error occurrence
+   LASTERR="$2"          # error code
+   echo "ERROR exit from ${SCRIPT} : line ${LASTLINE} with exit code ${LASTERR}"
+   exit 1
+}
+trap 'error ${LINENO} ${?}' ERR
+
+
+#check input parameters
+if [ $# -eq 0 ]; then
+  echo "Usage : port_offset_util.sh set PORT_OFFSET --> Modify all conflict ports base on a offset"
+  echo "Usage : port_offset_util.sh reset --> Recover to original setting"
+  exit 0
+fi
+
+#check kylin home
+if [ -z "$KYLIN_HOME" ]
+then
+    echo 'Please make sure KYLIN_HOME has been set'
+    exit 1
+else
+    echo "KYLIN_HOME is set to ${KYLIN_HOME}"
+fi
+
+#variables
+TOMCAT_BACKUP_FILE="${KYLIN_HOME}/tomcat/conf/server.xml.backup"
+TOMCAT_CONFIG_FILE="${KYLIN_HOME}/tomcat/conf/server.xml"
+KYLIN_CONFIG_FILE="${KYLIN_HOME}/conf/kylin.properties"
+KYLIN_BACKUP_FILE="${KYLIN_HOME}/conf/kylin.properties.backup"
+TOMCAT_PORT_LIST=(9005 7070 9443 7443 9009)
+KYLIN_DEFAULT_PORT=7070
+
+if [ "$1" == "set" ] 
+then
+    OFFSET=$2
+    echo "Port offset is : ${OFFSET}"
+
+    #check config file exist
+    if [ ! -f ${KYLIN_CONFIG_FILE} ] || [ ! -f ${TOMCAT_CONFIG_FILE} ]; then
+        echo "Some of the config file not exist"
+        exit 1
+    fi
+
+    #back or reset
+    if [ ! -f ${KYLIN_BACKUP_FILE} ]; then  #backup if not exist
+        cp -f ${KYLIN_CONFIG_FILE} ${KYLIN_BACKUP_FILE}
+    else
+        cp -r ${KYLIN_BACKUP_FILE} ${KYLIN_CONFIG_FILE} #reset if exist
+    fi
+
+    if [ ! -f ${TOMCAT_BACKUP_FILE} ]; then  #backup if not exist
+        cp -f ${TOMCAT_CONFIG_FILE} ${TOMCAT_BACKUP_FILE}
+    else
+        cp -r ${TOMCAT_BACKUP_FILE} ${TOMCAT_CONFIG_FILE} #reset if exist
+    fi
+
+    #replace ports in kylin.properties
+    new_kylin_port=`expr ${KYLIN_DEFAULT_PORT} + ${OFFSET}`
+
+    sed -i "s/kylin.server.cluster-servers=\(.*\).*:\(.*\)/kylin.server.cluster-servers=\1:${new_kylin_port}/g" ${KYLIN_CONFIG_FILE}
+
+    echo "New kylin port is : ${new_kylin_port}"
+
+    #replace ports in server.xml
+
+    for port in ${TOMCAT_PORT_LIST[@]}
+    do
+      new_port=`expr ${port} + ${OFFSET} `
+      #echo "Replace old port : ${port} to new port : ${new_port}"
+      sed -i "s/$port/${new_port}/g" ${TOMCAT_CONFIG_FILE}
+
+    done
+    echo "Files below modified:"
+    echo ${KYLIN_CONFIG_FILE}
+    echo ${TOMCAT_CONFIG_FILE}
+elif [ "$1" == "reset" ]
+then
+    #reset kylin.properties
+    cp  -f ${KYLIN_BACKUP_FILE} ${KYLIN_CONFIG_FILE}
+    cp  -f ${TOMCAT_BACKUP_FILE} ${TOMCAT_CONFIG_FILE}
+    rm  -f ${KYLIN_BACKUP_FILE}
+    rm  -f ${TOMCAT_BACKUP_FILE}
+    echo "Files below reset to original:"
+    echo ${KYLIN_CONFIG_FILE}
+    echo ${TOMCAT_CONFIG_FILE}
+else
+    echo "Unrecognized command"
+    exit 1
+fi