You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by wa...@apache.org on 2022/07/28 06:12:25 UTC

[incubator-pegasus] branch master updated: refactor(build): skip re-generating thrift and skip re-cmaking (#1082)

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

wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new 422cb2d23 refactor(build): skip re-generating thrift and skip re-cmaking (#1082)
422cb2d23 is described below

commit 422cb2d237345d696bb7b2caa04db9382d2c913d
Author: Yingchun Lai <la...@apache.org>
AuthorDate: Thu Jul 28 14:12:20 2022 +0800

    refactor(build): skip re-generating thrift and skip re-cmaking (#1082)
---
 .github/workflows/lint_and_test_cpp.yaml  |  44 ++++++++---
 .rat-excludes                             |   1 -
 run.sh                                    | 125 +++++++++++++-----------------
 scripts/clear_zk.sh                       |  11 ++-
 scripts/collector_table_counter_gen.py    |   0
 scripts/config_hdfs.sh                    |   2 +
 scripts/downgrade_node.sh                 |   2 +
 scripts/format_files.sh                   |   2 +
 scripts/{get_local_ip => get_local_ip.py} |  46 ++---------
 scripts/migrate_node.sh                   |   2 +
 scripts/minos_common.sh                   |   2 +
 scripts/pack_client.sh                    |   2 +
 scripts/pack_common.sh                    |   2 +
 scripts/pack_server.sh                    |   2 +
 scripts/pack_tools.sh                     |   2 +
 scripts/pegasus_add_node_list.sh          |   5 +-
 scripts/pegasus_bench_run.sh              |   4 +-
 scripts/pegasus_check_arguments.sh        |   5 +-
 scripts/pegasus_kill_test.sh              |   2 +
 scripts/pegasus_manual_compact.sh         |   2 +
 scripts/pegasus_migrate_zookeeper.sh      |   5 +-
 scripts/pegasus_offline_node.sh           |   5 +-
 scripts/pegasus_offline_node_list.sh      |   5 +-
 scripts/pegasus_rebalance_cluster.sh      |   7 +-
 scripts/pegasus_replica_thread.sh         |   2 +
 scripts/pegasus_restart_node.sh           |   5 +-
 scripts/pegasus_rolling_update.sh         |   4 +-
 scripts/pegasus_set_usage_scenario.sh     |   2 +
 scripts/pegasus_stat_available.sh         |   2 +
 scripts/pegasus_update_ingest_behind.sh   |   5 +-
 scripts/sendmail.sh                       |   2 +
 scripts/start_zk.sh                       |   4 +-
 scripts/stop_zk.sh                        |  10 ++-
 33 files changed, 175 insertions(+), 146 deletions(-)

diff --git a/.github/workflows/lint_and_test_cpp.yaml b/.github/workflows/lint_and_test_cpp.yaml
index 0ad2914c9..02d7f15a5 100644
--- a/.github/workflows/lint_and_test_cpp.yaml
+++ b/.github/workflows/lint_and_test_cpp.yaml
@@ -74,6 +74,10 @@ jobs:
         id: changes
         with:
           filters: |
+            base:
+              - 'cmake_modules/**'
+              - 'CMakeLists.txt'
+              - 'run.sh'
             rdsn:
               - 'src/rdsn/**'
             thirdparty:
@@ -89,10 +93,10 @@ jobs:
           cmake -DCMAKE_BUILD_TYPE=Release -B build/
           cmake --build build/ -j $(($(nproc)/2+1))
       - name: Compilation
-        if: steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: ./run.sh build -c --rdsn --test --skip_thirdparty -j $(($(nproc)/2+1))
       - name: Unit Testing
-        if: steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: |
           export LD_LIBRARY_PATH=`pwd`/thirdparty/output/lib:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server
           ulimit -s unlimited
@@ -118,6 +122,10 @@ jobs:
         id: changes
         with:
           filters: |
+            base:
+              - 'cmake_modules/**'
+              - 'CMakeLists.txt'
+              - 'run.sh'
             rdsn:
               - 'src/rdsn/**'
             thirdparty:
@@ -133,10 +141,10 @@ jobs:
           cmake -DCMAKE_BUILD_TYPE=Release -B build/
           cmake --build build/ -j $(($(nproc)/2+1))
       - name: Compilation
-        if: steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: ./run.sh build -c --rdsn --test --sanitizer address --skip_thirdparty --disable_gperf -j $(($(nproc)/2+1))
       - name: Unit Testing
-        if: steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: |
           export LD_LIBRARY_PATH=`pwd`/thirdparty/output/lib:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server
           ulimit -s unlimited
@@ -162,6 +170,10 @@ jobs:
         id: changes
         with:
           filters: |
+            base:
+              - 'cmake_modules/**'
+              - 'CMakeLists.txt'
+              - 'run.sh'
             rdsn:
               - 'src/rdsn/**'
             thirdparty:
@@ -177,10 +189,10 @@ jobs:
           cmake -DCMAKE_BUILD_TYPE=Release -B build/
           cmake --build build/ -j $(($(nproc)/2+1))
       - name: Compilation
-        if: steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: ./run.sh build -c --rdsn --test --sanitizer leak --skip_thirdparty --disable_gperf -j $(($(nproc)/2+1))
       - name: Unit Testing
-        if: steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: |
           export LD_LIBRARY_PATH=`pwd`/thirdparty/output/lib:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server
           ulimit -s unlimited
@@ -206,6 +218,10 @@ jobs:
         id: changes
         with:
           filters: |
+            base:
+              - 'cmake_modules/**'
+              - 'CMakeLists.txt'
+              - 'run.sh'
             rdsn:
               - 'src/rdsn/**'
             thirdparty:
@@ -221,10 +237,10 @@ jobs:
           cmake -DCMAKE_BUILD_TYPE=Release -B build/
           cmake --build build/ -j $(($(nproc)/2+1))
       - name: Compilation
-        if: steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: ./run.sh build -c --rdsn --test --sanitizer undefined --skip_thirdparty --disable_gperf -j $(($(nproc)/2+1))
       - name: Unit Testing
-        if: steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.rdsn == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: |
           export LD_LIBRARY_PATH=`pwd`/thirdparty/output/lib:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server
           ulimit -s unlimited
@@ -246,6 +262,10 @@ jobs:
         id: changes
         with:
           filters: |
+            base:
+              - 'cmake_modules/**'
+              - 'CMakeLists.txt'
+              - 'run.sh'
             pegasus:
               - 'src/**'
             thirdparty:
@@ -261,16 +281,16 @@ jobs:
           cmake -DCMAKE_BUILD_TYPE=Release -B build/
           cmake --build build/ -j $(($(nproc)/2+1))
       - name: Compilation
-        if: steps.changes.outputs.pegasus == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.pegasus == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: ./run.sh build --test -c -j $(($(nproc)/2+1))
       - name: Packaging Server
-        if: steps.changes.outputs.pegasus == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.pegasus == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: ./run.sh pack_server
       - name: Packaging Tools
-        if: steps.changes.outputs.pegasus == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.pegasus == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: ./run.sh pack_tools
       - name: Unit Testing
-        if: steps.changes.outputs.pegasus == 'true' || steps.changes.outputs.thirdparty == 'true'
+        if: steps.changes.outputs.base == 'true' || steps.changes.outputs.pegasus == 'true' || steps.changes.outputs.thirdparty == 'true'
         run: |
           source ./scripts/config_hdfs.sh
           ./run.sh test --on_travis
diff --git a/.rat-excludes b/.rat-excludes
index 3fd7af177..ef48d7fff 100644
--- a/.rat-excludes
+++ b/.rat-excludes
@@ -7,7 +7,6 @@ argh.h
 git_commit.h
 ssh-no-interactive
 scp-no-interactive
-get_local_ip
 DISCLAIMER-WIP
 .rat-excludes
 apache-rat-0.13.jar
diff --git a/run.sh b/run.sh
index ebb65e1fb..e22befbf0 100755
--- a/run.sh
+++ b/run.sh
@@ -16,9 +16,11 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 PID=$$
 ROOT=`pwd`
-LOCAL_IP=`scripts/get_local_ip`
+LOCAL_IP=`python3 scripts/get_local_ip.py`
 export REPORT_DIR="$ROOT/test_report"
 export DSN_ROOT=$ROOT/DSN_ROOT
 export THIRDPARTY_ROOT=$ROOT/thirdparty
@@ -249,81 +251,68 @@ function run_build()
     fi
 
     echo "INFO: Start build rdsn..."
-    echo "Gen rdsn thrift"
-    python3 $ROOT/scripts/compile_thrift.py
     BUILD_DIR="$ROOT/src/rdsn/builder"
     if [ "$CLEAR" == "YES" ]; then
         echo "Clear $BUILD_DIR ..."
         rm -rf $BUILD_DIR
     fi
-    echo "Running cmake..."
     if [ ! -d "$BUILD_DIR" ]; then
         mkdir -p $BUILD_DIR
+
+        echo "Gen rdsn thrift"
+        python3 $ROOT/scripts/compile_thrift.py
+
+        echo "Running cmake rdsn ..."
+        pushd $BUILD_DIR
+        CMAKE_OPTIONS="${CMAKE_OPTIONS} -DBUILD_TEST=${BUILD_TEST}"
+        cmake ../../.. -DCMAKE_INSTALL_PREFIX=$BUILD_DIR/output $CMAKE_OPTIONS -DBUILD_RDSN=ON -DBUILD_PEGASUS=OFF
+        exit_if_fail $?
     fi
+
+    echo "[$(date)] Building rdsn ..."
     pushd $BUILD_DIR
-    CMAKE_OPTIONS="${CMAKE_OPTIONS} -DBUILD_TEST=${BUILD_TEST}"
-    cmake ../../.. -DCMAKE_INSTALL_PREFIX=$BUILD_DIR/output $CMAKE_OPTIONS -DBUILD_RDSN=ON -DBUILD_PEGASUS=OFF
-    if [ $? -ne 0 ]; then
-        echo "ERROR: cmake rdsn failed"
-        exit 1
-    fi
-    echo "[$(date)] Building..."
     make install $MAKE_OPTIONS
-    if [ $? -ne 0 ]
-    then
-        echo "ERROR: build failed"
-        exit 1
-    else
-        echo "[$(date)] Build succeed"
-    fi
-    popd
+    exit_if_fail $?
 
     if [ "$ONLY_RDSN" == "YES" ]; then
       exit 0
     fi
 
-    echo "INFO: start build pegasus..."
-    echo "Gen pegasus thrift"
-    sh scripts/recompile_thrift.sh
-
-    cd "$ROOT/src"
-    PEGASUS_GIT_COMMIT="non-git-repo"
-    if git rev-parse HEAD; then # this is a git repo
-        PEGASUS_GIT_COMMIT=$(git rev-parse HEAD)
-    fi
-    echo "PEGASUS_GIT_COMMIT=${PEGASUS_GIT_COMMIT}"
-    GIT_COMMIT_FILE=include/pegasus/git_commit.h
-    echo "Generating $GIT_COMMIT_FILE..."
-    echo "#pragma once" >$GIT_COMMIT_FILE
-    echo "#define PEGASUS_GIT_COMMIT \"$PEGASUS_GIT_COMMIT\"" >>$GIT_COMMIT_FILE
-
+    echo "INFO: start build Pegasus..."
     BUILD_DIR="$ROOT/src/builder"
     if [ "$CLEAR" == "YES" ]; then
         echo "Clear $BUILD_DIR ..."
         rm -rf $BUILD_DIR
     fi
-    echo "Running cmake..."
+    pushd ${ROOT}
     if [ ! -d "$BUILD_DIR" ]; then
         mkdir -p $BUILD_DIR
+
+        echo "Gen git_commit.h ..."
+        pushd "$ROOT/src"
+        PEGASUS_GIT_COMMIT="non-git-repo"
+        if git rev-parse HEAD; then # this is a git repo
+            PEGASUS_GIT_COMMIT=$(git rev-parse HEAD)
+        fi
+        echo "PEGASUS_GIT_COMMIT=${PEGASUS_GIT_COMMIT}"
+        GIT_COMMIT_FILE=$ROOT/src/include/pegasus/git_commit.h
+        echo "Generating $GIT_COMMIT_FILE..."
+        echo "#pragma once" >$GIT_COMMIT_FILE
+        echo "#define PEGASUS_GIT_COMMIT \"$PEGASUS_GIT_COMMIT\"" >>$GIT_COMMIT_FILE
+
+        echo "Gen pegasus thrift"
+        sh ${ROOT}/scripts/recompile_thrift.sh
+
+        echo "Running cmake Pegasus..."
+        pushd $BUILD_DIR
+        cmake ../.. -DCMAKE_INSTALL_PREFIX=$BUILD_DIR/output $CMAKE_OPTIONS -DBUILD_RDSN=OFF -DBUILD_PEGASUS=ON
+        exit_if_fail $?
     fi
+
+    echo "[$(date)] Building Pegasus ..."
     pushd $BUILD_DIR
-    cmake ../.. -DCMAKE_INSTALL_PREFIX=$BUILD_DIR/output $CMAKE_OPTIONS -DBUILD_RDSN=OFF -DBUILD_PEGASUS=ON
-    if [ $? -ne 0 ]; then
-        echo "ERROR: cmake pegasus failed"
-        exit 1
-    fi
-    echo "[$(date)] Building..."
     make install $MAKE_OPTIONS
-    if [ $? -ne 0 ]
-    then
-        echo "ERROR: build failed"
-        exit 1
-    else
-        echo "[$(date)] Build succeed"
-    fi
-
-    cd $ROOT
-    chmod +x scripts/*.sh
+    exit_if_fail $?
 
     echo "Build finish time: `date`"
     finish_time=`date +%s`
@@ -388,12 +377,6 @@ function run_test()
     echo "Test start time: `date`"
     start_time=`date +%s`
 
-    run_start_zk
-    if [ $? -ne 0 ]; then
-        echo "ERROR: start zk failed"
-        exit 1
-    fi
-
     if [ ! -d "$REPORT_DIR" ]; then
         mkdir -p $REPORT_DIR
     fi
@@ -442,13 +425,14 @@ function run_pegasus_test()
         echo "Prepare files used for bulk load function test succeed"
     fi
 
-    ./run.sh clear_onebox #clear the onebox before test
-    if ! ./run.sh start_onebox -w; then
+    # restart onebox
+    run_clear_onebox
+    if ! run_start_onebox -w; then
         echo "ERROR: unable to continue on testing because starting onebox failed"
         exit 1
     fi
 
-    sed -i "s/@LOCAL_IP@/${LOCAL_IP}/g"  $ROOT/src/builder/server/test/config.ini
+    sed -i "s/@LOCAL_IP@/${LOCAL_IP}/g"  $ROOT/src/builder/src/server/test/config.ini
 
     for module in `echo $test_modules | sed 's/,/ /g'`; do
         echo "====================== run $module =========================="
@@ -462,7 +446,7 @@ function run_pegasus_test()
     done
 
     if [ "$clear_flags" == "1" ]; then
-        ./run.sh clear_onebox
+        run_clear_onebox
     fi
 }
 function run_rdsn_test()
@@ -472,6 +456,10 @@ function run_rdsn_test()
     fi
     echo "test_modules=$test_modules"
 
+    # restart zk
+    run_stop_zk
+    run_start_zk
+
     for module in `echo $test_modules | sed 's/,/ /g'`; do
         echo "====================== run $module =========================="
         pushd $ROOT/src/rdsn/builder/bin/$module
@@ -535,9 +523,6 @@ function run_start_zk()
     done
 
     INSTALL_DIR="$INSTALL_DIR" PORT="$PORT" $ROOT/scripts/start_zk.sh
-    if [ $? -ne 0 ]; then
-        exit 1
-    fi
 }
 
 #####################
@@ -842,7 +827,7 @@ function run_stop_onebox()
         esac
         shift
     done
-    ps -ef | grep '/pegasus_server config.ini' | grep -E 'app_list meta|app_list replica|app_list collector' | awk '{print $2}' | xargs kill &>/dev/null
+    ps -ef | grep '/pegasus_server config.ini' | grep -E 'app_list meta|app_list replica|app_list collector' | awk '{print $2}' | xargs kill &>/dev/null || true
 }
 
 #####################
@@ -1070,7 +1055,7 @@ function run_stop_onebox_instance()
             echo "INFO: meta@$META_ID is not running"
             exit 1
         fi
-        ps -ef | grep "/meta$META_ID/pegasus_server config.ini" | grep "app_list meta" | awk '{print $2}' | xargs kill &>/dev/null
+        ps -ef | grep "/meta$META_ID/pegasus_server config.ini" | grep "app_list meta" | awk '{print $2}' | xargs kill &>/dev/null || true
         echo "INFO: meta@$META_ID stopped"
     fi
     if [ $REPLICA_ID != "0" ]; then
@@ -1083,7 +1068,7 @@ function run_stop_onebox_instance()
             echo "INFO: replica@$REPLICA_ID is not running"
             exit 1
         fi
-        ps -ef | grep "/replica$REPLICA_ID/pegasus_server config.ini" | grep "app_list replica" | awk '{print $2}' | xargs kill &>/dev/null
+        ps -ef | grep "/replica$REPLICA_ID/pegasus_server config.ini" | grep "app_list replica" | awk '{print $2}' | xargs kill &>/dev/null || true
         echo "INFO: replica@$REPLICA_ID stopped"
     fi
     if [ $COLLECTOR_ID != "0" ]; then
@@ -1091,7 +1076,7 @@ function run_stop_onebox_instance()
             echo "INFO: collector is not running"
             exit 1
         fi
-        ps -ef | grep "/collector/pegasus_server config.ini" | grep "app_list collector" | awk '{print $2}' | xargs kill &>/dev/null
+        ps -ef | grep "/collector/pegasus_server config.ini" | grep "app_list collector" | awk '{print $2}' | xargs kill &>/dev/null || true
         echo "INFO: collector stopped"
     fi
 }
@@ -1307,7 +1292,7 @@ function run_stop_kill_test()
         shift
     done
 
-    ps -ef | grep '/pegasus_kill_test ' | awk '{print $2}' | xargs kill &>/dev/null
+    ps -ef | grep '/pegasus_kill_test ' | awk '{print $2}' | xargs kill &>/dev/null || true
     run_stop_onebox
 }
 
@@ -1537,7 +1522,7 @@ function run_stop_upgrade_test()
         shift
     done
 
-    ps -ef | grep ' \./pegasus_upgrade_test ' | awk '{print $2}' | xargs kill &>/dev/null
+    ps -ef | grep ' \./pegasus_upgrade_test ' | awk '{print $2}' | xargs kill &>/dev/null || true
     run_stop_onebox
 }
 
diff --git a/scripts/clear_zk.sh b/scripts/clear_zk.sh
index a31a90e12..c94cbe03a 100755
--- a/scripts/clear_zk.sh
+++ b/scripts/clear_zk.sh
@@ -15,7 +15,9 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # Options:
 #    INSTALL_DIR    <dir>
 
@@ -25,8 +27,13 @@ then
     exit 1
 fi
 
-cd $INSTALL_DIR
+if [ ! -d "$INSTALL_DIR" ]
+then
+    # ignore zookeeper INSTALL_DIR not exist when stop zookeeper
+    exit 0
+fi
 
+cd $INSTALL_DIR
 ZOOKEEPER_HOME=`pwd`/apache-zookeeper-3.7.0-bin
 
 if [ -d "$ZOOKEEPER_HOME" ]
diff --git a/scripts/collector_table_counter_gen.py b/scripts/collector_table_counter_gen.py
old mode 100644
new mode 100755
diff --git a/scripts/config_hdfs.sh b/scripts/config_hdfs.sh
index da9b4b01f..32aa0375c 100755
--- a/scripts/config_hdfs.sh
+++ b/scripts/config_hdfs.sh
@@ -17,6 +17,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 # This file should be sourced to set up LD_LIBRARY_PATH and CLASSPATH to
 # run Pegasus binaries which use libhdfs in the context of a dev environment.
 
diff --git a/scripts/downgrade_node.sh b/scripts/downgrade_node.sh
index 238454f2d..a8e80892b 100755
--- a/scripts/downgrade_node.sh
+++ b/scripts/downgrade_node.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 PID=$$
 
 if [ $# -ne 4 ]
diff --git a/scripts/format_files.sh b/scripts/format_files.sh
index 1ac0e8d85..5697d720b 100755
--- a/scripts/format_files.sh
+++ b/scripts/format_files.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 pwd="$( cd "$( dirname "$0"  )" && pwd )"
 root_dir="$( cd $pwd/.. && pwd )"
 cd $root_dir
diff --git a/scripts/get_local_ip b/scripts/get_local_ip.py
similarity index 51%
rename from scripts/get_local_ip
rename to scripts/get_local_ip.py
index 981d5706f..09c034f34 100755
--- a/scripts/get_local_ip
+++ b/scripts/get_local_ip.py
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env python
 # 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
@@ -16,43 +16,13 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# $1: string
-# print 1 for success, 0 for fail
-function is_ipv4() 
-{
-    if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
-        echo "1"
-    else
-        echo "0"
-    fi
-}
+import socket
 
-# $1: an ip_addr
-function is_site_local_addr()
-{
-    # 10.*.*.*
-    if [[ $1 =~ ^10\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
-        echo "1"
-    # 172.16.*.*
-    elif [[ $1 =~ ^172\.16\.[0-9]+\.[0-9]+$ ]]; then
-        echo "1"
-    # 192.168.*.*
-    elif [[ $1 =~ ^192\.168\.[0-9]+\.[0-9]+$ ]]; then
-        echo "1"
-    else
-        echo "0"
-    fi
-}
 
-got_result="0"
-for ip in `hostname -I`; do 
-    if [ "1" == `is_site_local_addr $ip` ]; then
-        echo $ip
-        got_result="1"
-        break
-    fi
-done
+def get_host_ip():
+    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
+        s.connect(('8.8.8.8', 80))
+        return s.getsockname()[0]
 
-if [ "0" == $got_result ]; then
-    echo "127.0.0.1"
-fi
+
+print(get_host_ip())
diff --git a/scripts/migrate_node.sh b/scripts/migrate_node.sh
index d0fae1a27..f19552a9a 100755
--- a/scripts/migrate_node.sh
+++ b/scripts/migrate_node.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 PID=$$
 
 if [ $# -ne 4 ]
diff --git a/scripts/minos_common.sh b/scripts/minos_common.sh
index 41b5bf5cf..eb0321de3 100755
--- a/scripts/minos_common.sh
+++ b/scripts/minos_common.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 #
 # You should set these environment variables:
 #   * MINOS_CONFIG_FILE
diff --git a/scripts/pack_client.sh b/scripts/pack_client.sh
index 9fa9bdf4b..519255df2 100755
--- a/scripts/pack_client.sh
+++ b/scripts/pack_client.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 source $(dirname $0)/pack_common.sh
 
 function usage()
diff --git a/scripts/pack_common.sh b/scripts/pack_common.sh
index 7d60397b5..55b312746 100755
--- a/scripts/pack_common.sh
+++ b/scripts/pack_common.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 function get_stdcpp_lib()
 {
     libname=`ldd ./DSN_ROOT/bin/pegasus_server/pegasus_server 2>/dev/null | grep libstdc++`
diff --git a/scripts/pack_server.sh b/scripts/pack_server.sh
index fcda65cf5..60d8aa493 100755
--- a/scripts/pack_server.sh
+++ b/scripts/pack_server.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 source $(dirname $0)/pack_common.sh
 
 function usage() {
diff --git a/scripts/pack_tools.sh b/scripts/pack_tools.sh
index 7a2547ee4..924c33ab4 100755
--- a/scripts/pack_tools.sh
+++ b/scripts/pack_tools.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 source $(dirname $0)/pack_common.sh
 
 function usage()
diff --git a/scripts/pegasus_add_node_list.sh b/scripts/pegasus_add_node_list.sh
index 049d72491..ed40a8b6d 100755
--- a/scripts/pegasus_add_node_list.sh
+++ b/scripts/pegasus_add_node_list.sh
@@ -15,9 +15,10 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # Add replica servers using minos.
-#
 
 PID=$$
 
diff --git a/scripts/pegasus_bench_run.sh b/scripts/pegasus_bench_run.sh
index 9eb08ff0a..28070c269 100755
--- a/scripts/pegasus_bench_run.sh
+++ b/scripts/pegasus_bench_run.sh
@@ -15,7 +15,9 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # test pegasus_bench with thread 1~50
 
 pwd="$( cd "$( dirname "$0"  )" && pwd )"
diff --git a/scripts/pegasus_check_arguments.sh b/scripts/pegasus_check_arguments.sh
index 06f197705..4b0231d87 100755
--- a/scripts/pegasus_check_arguments.sh
+++ b/scripts/pegasus_check_arguments.sh
@@ -15,9 +15,10 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # Check offline_node_list.sh and add_node_list.sh arguments.
-#
 
 PID=$$
 
diff --git a/scripts/pegasus_kill_test.sh b/scripts/pegasus_kill_test.sh
index 77d27ef8e..da33ce236 100755
--- a/scripts/pegasus_kill_test.sh
+++ b/scripts/pegasus_kill_test.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 if [ $# -ne 5 ]
 then
     echo "USAGE: $0 <meta-count> <replica-count> <app-name> <kill-type> <sleep-time>"
diff --git a/scripts/pegasus_manual_compact.sh b/scripts/pegasus_manual_compact.sh
index 19be39614..cd9c2da6c 100755
--- a/scripts/pegasus_manual_compact.sh
+++ b/scripts/pegasus_manual_compact.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 PID=$$
 
 function usage()
diff --git a/scripts/pegasus_migrate_zookeeper.sh b/scripts/pegasus_migrate_zookeeper.sh
index 5cfd4d806..52e7c0952 100755
--- a/scripts/pegasus_migrate_zookeeper.sh
+++ b/scripts/pegasus_migrate_zookeeper.sh
@@ -15,9 +15,10 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # Migrate zookeeper using minos.
-#
 
 PID=$$
 
diff --git a/scripts/pegasus_offline_node.sh b/scripts/pegasus_offline_node.sh
index d1a9b73ec..d16f368f1 100755
--- a/scripts/pegasus_offline_node.sh
+++ b/scripts/pegasus_offline_node.sh
@@ -15,9 +15,10 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # Offline replica server using minos.
-#
 
 PID=$$
 
diff --git a/scripts/pegasus_offline_node_list.sh b/scripts/pegasus_offline_node_list.sh
index 29d391d70..7a2483f49 100755
--- a/scripts/pegasus_offline_node_list.sh
+++ b/scripts/pegasus_offline_node_list.sh
@@ -15,9 +15,10 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # Offline replica servers using minos.
-#
 
 PID=$$
 
diff --git a/scripts/pegasus_rebalance_cluster.sh b/scripts/pegasus_rebalance_cluster.sh
index aae389289..bb816f7d3 100755
--- a/scripts/pegasus_rebalance_cluster.sh
+++ b/scripts/pegasus_rebalance_cluster.sh
@@ -15,9 +15,10 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
-# Pegasus cluster rebalance 
-#
+
+set -e
+
+# Pegasus cluster rebalance
 
 PID=$$
 
diff --git a/scripts/pegasus_replica_thread.sh b/scripts/pegasus_replica_thread.sh
index e0f8577fa..9de115bdb 100755
--- a/scripts/pegasus_replica_thread.sh
+++ b/scripts/pegasus_replica_thread.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 PID=$$
 
 if [ $# -ne 3 ]
diff --git a/scripts/pegasus_restart_node.sh b/scripts/pegasus_restart_node.sh
index c56a989f9..b65e6ec18 100755
--- a/scripts/pegasus_restart_node.sh
+++ b/scripts/pegasus_restart_node.sh
@@ -15,9 +15,10 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # Restart replica server using minos.
-#
 
 PID=$$
 
diff --git a/scripts/pegasus_rolling_update.sh b/scripts/pegasus_rolling_update.sh
index a604127a5..9e207fc30 100755
--- a/scripts/pegasus_rolling_update.sh
+++ b/scripts/pegasus_rolling_update.sh
@@ -15,9 +15,9 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
 # Rolling update pegasus cluster using minos.
-#
 
 PID=$$
 
diff --git a/scripts/pegasus_set_usage_scenario.sh b/scripts/pegasus_set_usage_scenario.sh
index 3055967d1..9fb606dec 100755
--- a/scripts/pegasus_set_usage_scenario.sh
+++ b/scripts/pegasus_set_usage_scenario.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 PID=$$
 
 if [ $# -ne 3 ]
diff --git a/scripts/pegasus_stat_available.sh b/scripts/pegasus_stat_available.sh
index 227eec201..1ed2829ff 100755
--- a/scripts/pegasus_stat_available.sh
+++ b/scripts/pegasus_stat_available.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 PID=$$
 
 if [ $# -lt 2 ]; then
diff --git a/scripts/pegasus_update_ingest_behind.sh b/scripts/pegasus_update_ingest_behind.sh
index 567264e26..8932f667e 100755
--- a/scripts/pegasus_update_ingest_behind.sh
+++ b/scripts/pegasus_update_ingest_behind.sh
@@ -15,9 +15,10 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # Update app ingestion_behind envs using minos.
-#
 
 PID=$$
 
diff --git a/scripts/sendmail.sh b/scripts/sendmail.sh
index ecbdcce8c..f374abf00 100755
--- a/scripts/sendmail.sh
+++ b/scripts/sendmail.sh
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+set -e
+
 ### send alert email
 ### usage:
 ###    bash sendmail.sh alert <alert_email_address> <cluster_name> <table_name> <partition_index>
diff --git a/scripts/start_zk.sh b/scripts/start_zk.sh
index f8dcf54e2..fe22f0dca 100755
--- a/scripts/start_zk.sh
+++ b/scripts/start_zk.sh
@@ -15,7 +15,9 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
+
 # Options:
 #    INSTALL_DIR    <dir>
 #    PORT           <port>
diff --git a/scripts/stop_zk.sh b/scripts/stop_zk.sh
index da06a91bf..313fd4f54 100755
--- a/scripts/stop_zk.sh
+++ b/scripts/stop_zk.sh
@@ -15,7 +15,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-#
+
+set -e
 # Options:
 #    INSTALL_DIR    <dir>
 
@@ -25,8 +26,13 @@ then
     exit 1
 fi
 
-cd $INSTALL_DIR
+if [ ! -d "$INSTALL_DIR" ]
+then
+    # ignore zookeeper INSTALL_DIR not exist when stop zookeeper
+    exit 0
+fi
 
+cd $INSTALL_DIR
 ZOOKEEPER_HOME=`pwd`/apache-zookeeper-3.7.0-bin
 
 if [ -d "$ZOOKEEPER_HOME" ]


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org