zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject svn commit: r1457598 - in /zookeeper/bookkeeper/trunk: CHANGES.txt bookkeeper-server/bin/bookkeeper-cluster.sh
Date Sun, 17 Mar 2013 23:40:07 GMT
Author: sijie
Date: Sun Mar 17 23:40:07 2013
New Revision: 1457598

URL: http://svn.apache.org/r1457598
Log:
BOOKKEEPER-573: Script to start a bookkeeper cluster (ivank via sijie)

Added:
    zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-cluster.sh
Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1457598&r1=1457597&r2=1457598&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Sun Mar 17 23:40:07 2013
@@ -48,6 +48,8 @@ Trunk (unreleased changes)
 
       BOOKKEEPER-585: Auditor logs noisily when a ledger has been deleted (ivank via sijie)
 
+      BOOKKEEPER-573: Script to start a bookkeeper cluster (ivank via sijie)
+
 Release 4.2.0 - 2013-01-14
 
   Non-backward compatible changes:

Added: zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-cluster.sh
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-cluster.sh?rev=1457598&view=auto
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-cluster.sh (added)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/bin/bookkeeper-cluster.sh Sun Mar 17 23:40:07
2013
@@ -0,0 +1,135 @@
+#!/usr/bin/env bash
+#
+#/**
+# * 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
+# * regarding copyright ownership.  The ASF licenses this file
+# * to you under the Apache License, Version 2.0 (the
+# * "License"); you may not use this file except in compliance
+# * with the License.  You may obtain a copy of the License at
+# *
+# *     http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+# */
+
+
+BINDIR=`dirname "$0"`
+BK_HOME=`cd $BINDIR/..;pwd`
+if [ -f $BK_HOME/conf/bkenv.sh ]
+then
+ . $BK_HOME/conf/bkenv.sh
+fi
+
+BKCFG=$BK_HOME/conf/bk_server.conf
+CLUSTER=$BK_HOME/conf/bookies
+usage() {
+    cat <<EOF
+Usage: bookkeeper-cluster.sh (start|stop|kill)
+
+The list of hosts in the cluster must be available in
+$CLUSTER
+with one hostname per line.
+
+BookKeeper must be installed in the same location on each host.
+EOF
+}
+
+if [ ! -f $CLUSTER ]; then
+    echo -e "\nCluster file ($CLUSTER) does not exist\n"
+    usage
+    exit 1
+fi
+
+NUMHOSTS=$(wc -l $CLUSTER | awk '{print $1}')
+if [ "$NUMHOSTS" = "0" ]; then
+    echo -e "\nCluster file ($CLUSTER) is empty\n"
+    usage
+    exit 1
+fi
+
+bookies_list() {
+    $BINDIR/bookkeeper shell listbookies 2> /dev/null
+}
+
+bookies_available() {
+    bookies_list | wc -l
+}
+
+start() {
+    for B in `cat $CLUSTER`; do
+	echo "Starting bookie on $B"
+	ssh $B $BINDIR/bookkeeper-daemon.sh start bookie
+    done
+
+    BOOKIESSTARTED=0
+    COUNT=0
+
+    while [ $BOOKIESSTARTED -lt $NUMHOSTS ];  do
+	sleep 1
+	COUNT=$(($COUNT+1))
+	if [ $COUNT = 20 ]; then
+	    echo "Could not start all bookies"
+	    exit 1
+	fi
+
+	BOOKIESSTARTED=$(bookies_available)
+
+	echo "$BOOKIESSTARTED bookies started"
+    done
+}
+
+stop() {
+    for B in `cat $CLUSTER`; do
+	echo "Stopping bookie on $B"
+	ssh $B $BINDIR/bookkeeper-daemon.sh stop bookie $FORCE
+    done
+
+    COUNT=0
+    BOOKIESSTARTED=$NUMHOSTS
+    while [ $BOOKIESSTARTED -gt 0 ];  do
+	sleep 1
+	
+	COUNT=$((COUNT+1))
+	if [ $COUNT = 20 ]; then
+	    echo "Couldn not stop all bookies. $BOOKIESSTARTED still running"
+	    exit 2
+	fi
+
+	BOOKIESSTARTED=$(bookies_available)
+    done
+}
+
+status() {
+    BOOKIESSTARTED=$(bookies_available)
+    echo "$BOOKIESSTARTED bookies running"
+    COUNT=1
+    for b in $(bookies_list); do
+	echo "$COUNT: $b"
+	COUNT=$(($COUNT+1))
+    done
+}
+
+case $1 in
+    start)
+	start
+	;;
+    stop)
+	stop
+	;;
+    kill)
+	FORCE="-force"
+	stop
+	;;
+    status)
+	status
+	;;
+    *)
+	usage
+	;;
+esac



Mime
View raw message