"Fossies" - the Fresh Open Source Software Archive

Member "apache-zookeeper-3.5.6/zookeeper-client/zookeeper-client-c/tests/zkServer.sh" (8 Oct 2019, 5036 Bytes) of package /linux/misc/apache-zookeeper-3.5.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "zkServer.sh": 3.5.5_vs_3.5.6.

    1 #!/bin/bash
    2 #
    3 # Licensed to the Apache Software Foundation (ASF) under one
    4 # or more contributor license agreements.  See the NOTICE file
    5 # distributed with this work for additional information
    6 # regarding copyright ownership.  The ASF licenses this file
    7 # to you under the Apache License, Version 2.0 (the
    8 # "License"); you may not use this file except in compliance
    9 # with the License.  You may obtain a copy of the License at
   10 #
   11 #     http://www.apache.org/licenses/LICENSE-2.0
   12 #
   13 # Unless required by applicable law or agreed to in writing, software
   14 # distributed under the License is distributed on an "AS IS" BASIS,
   15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   16 # See the License for the specific language governing permissions and
   17 # limitations under the License.
   18 
   19 # This is the port where zookeeper server runs on.
   20 ZOOPORT=22181
   21 
   22 if [ "x$1" == "x" ]
   23 then
   24     echo "USAGE: $0 startClean|start|startReadOnly|stop hostPorts"
   25     exit 2
   26 fi
   27 
   28 case "`uname`" in
   29     CYGWIN*) cygwin=true ;;
   30     *) cygwin=false ;;
   31 esac
   32 
   33 if [ "x$1" == "xstartClean" ]
   34 then
   35     if [ "x${base_dir}" == "x" ]
   36     then
   37     rm -rf /tmp/zkdata
   38     else
   39     rm -rf "${base_dir}/build/tmp"
   40     fi
   41 fi
   42 
   43 if $cygwin
   44 then
   45     # cygwin has a "kill" in the shell itself, gets confused
   46     KILL=/bin/kill
   47 else
   48     KILL=kill
   49 fi
   50 
   51 # Make sure nothing is left over from before
   52 if [ -r "/tmp/zk.pid" ]
   53 then
   54 pid=`cat /tmp/zk.pid`
   55 $KILL -9 $pid
   56 rm -f /tmp/zk.pid
   57 fi
   58 
   59 if [ -r "${base_dir}/build/tmp/zk.pid" ]
   60 then
   61 pid=`cat "${base_dir}/build/tmp/zk.pid"`
   62 $KILL -9 $pid
   63 rm -f "${base_dir}/build/tmp/zk.pid"
   64 fi
   65 
   66 # [ZOOKEEPER-820] If lsof command is present, look for a process listening
   67 # on ZOOPORT and kill it. 
   68 which lsof &> /dev/null
   69 if [ $? -eq 0  ]
   70 then
   71     pid=`lsof -i :$ZOOPORT | grep LISTEN | awk '{print $2}'`
   72     if [ -n "$pid" ]
   73     then
   74         $KILL -9 $pid
   75     fi
   76 fi
   77 
   78 if [ "x${base_dir}" == "x" ]
   79 then
   80 zk_base="../../"
   81 else
   82 zk_base="${base_dir}"
   83 fi
   84 
   85 CLASSPATH="$CLASSPATH:${zk_base}/build/classes"
   86 CLASSPATH="$CLASSPATH:${zk_base}/conf"
   87 CLASSPATH="$CLASSPATH:${zk_base}/zookeeper-server/target/classes"
   88 
   89 for i in "${zk_base}"/build/lib/*.jar
   90 do
   91     CLASSPATH="$CLASSPATH:$i"
   92 done
   93 
   94 for d in "${zk_base}"/zookeeper-server/target/lib/*.jar
   95 do
   96     CLASSPATH="$d:$CLASSPATH"
   97 done
   98 
   99 for i in "${zk_base}"/zookeeper-server/src/main/resource/lib/*.jar
  100 do
  101     CLASSPATH="$CLASSPATH:$i"
  102 done
  103 
  104 CLASSPATH="$CLASSPATH:${CLOVER_HOME}/lib/clover*.jar"
  105 
  106 if $cygwin
  107 then
  108     CLASSPATH=`cygpath -wp "$CLASSPATH"`
  109 fi
  110 
  111 PROPERTIES="-Dzookeeper.extendedTypesEnabled=true -Dznode.container.checkIntervalMs=100"
  112 
  113 case $1 in
  114 start|startClean)
  115     if [ "x${base_dir}" == "x" ]
  116     then
  117         mkdir -p /tmp/zkdata
  118         java -cp "$CLASSPATH" $PROPERTIES org.apache.zookeeper.server.ZooKeeperServerMain $ZOOPORT /tmp/zkdata 3000 $ZKMAXCNXNS &> /tmp/zk.log &
  119         pid=$!
  120         echo -n $! > /tmp/zk.pid
  121     else
  122         mkdir -p "${base_dir}/build/tmp/zkdata"
  123         java -cp "$CLASSPATH" $PROPERTIES org.apache.zookeeper.server.ZooKeeperServerMain $ZOOPORT "${base_dir}/build/tmp/zkdata" 3000 $ZKMAXCNXNS &> "${base_dir}/build/tmp/zk.log" &
  124         pid=$!
  125         echo -n $pid > "${base_dir}/build/tmp/zk.pid"
  126     fi
  127 
  128     # wait max 120 seconds for server to be ready to server clients
  129     # this handles testing on slow hosts
  130     success=false
  131     for i in {1..120}
  132     do
  133         if ps -p $pid > /dev/null
  134         then
  135             java -cp "$CLASSPATH" $PROPERTIES org.apache.zookeeper.ZooKeeperMain -server localhost:$ZOOPORT ls / > /dev/null 2>&1
  136             if [ $? -ne 0  ]
  137             then
  138                 # server not up yet - wait
  139                 sleep 1
  140             else
  141                 # server is up and serving client connections
  142                 success=true
  143                 break
  144             fi
  145         else
  146             # server died - exit now
  147             echo -n " ZooKeeper server process failed"
  148             break
  149         fi
  150     done
  151 
  152     if $success
  153     then
  154         ## in case for debug, but generally don't use as it messes up the
  155         ## console test output
  156         echo -n " ZooKeeper server started"
  157     else
  158         echo -n " ZooKeeper server NOT started"
  159     fi
  160 
  161     ;;
  162 startReadOnly)
  163     if [ "x${base_dir}" == "x" ]
  164     then
  165         echo "this target is for unit tests only"
  166         exit 2
  167     else
  168         tmpdir="${base_dir}/build/tmp"
  169         mkdir -p "${tmpdir}/zkdata"
  170         rm -f "${tmpdir}/zkdata/myid" && echo 1 > "${tmpdir}/zkdata/myid"
  171 
  172         sed "s#TMPDIR#${tmpdir}#g" ${base_dir}/zookeeper-client/zookeeper-client-c/tests/quorum.cfg > "${tmpdir}/quorum.cfg"
  173 
  174         # force read-only mode
  175     PROPERTIES="$PROPERTIES -Dreadonlymode.enabled=true"
  176         java -cp "$CLASSPATH" $PROPERTIES org.apache.zookeeper.server.quorum.QuorumPeerMain ${tmpdir}/quorum.cfg &> "${tmpdir}/zk.log" &
  177         pid=$!
  178         echo -n $pid > "${base_dir}/build/tmp/zk.pid"
  179         sleep 3 # wait until read-only server is up
  180     fi
  181 
  182     ;;
  183 stop)
  184     # Already killed above
  185     ;;
  186 *)
  187     echo "Unknown command " + $1
  188     exit 2
  189 esac
  190