HBASE-26765 Minor refactor of async scanning code (#4121)
[hbase.git] / bin / zookeepers.sh
blob97bf41b605288c6923faf7f15b7c3c324207aae0
1 #!/usr/bin/env bash
3 #/**
4 # * Licensed to the Apache Software Foundation (ASF) under one
5 # * or more contributor license agreements. See the NOTICE file
6 # * distributed with this work for additional information
7 # * regarding copyright ownership. The ASF licenses this file
8 # * to you under the Apache License, Version 2.0 (the
9 # * "License"); you may not use this file except in compliance
10 # * with the License. You may obtain a copy of the License at
11 # *
12 # * http://www.apache.org/licenses/LICENSE-2.0
13 # *
14 # * Unless required by applicable law or agreed to in writing, software
15 # * distributed under the License is distributed on an "AS IS" BASIS,
16 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # * See the License for the specific language governing permissions and
18 # * limitations under the License.
19 # */
21 # Run a shell command on all zookeeper hosts.
23 # Environment Variables
25 # HBASE_CONF_DIR Alternate hbase conf dir. Default is ${HBASE_HOME}/conf.
26 # HBASE_SLAVE_SLEEP Seconds to sleep between spawning remote commands.
27 # HBASE_SSH_OPTS Options passed to ssh when running remote commands.
29 # Modelled after $HADOOP_HOME/bin/slaves.sh.
31 usage="Usage: zookeepers [--config <hbase-confdir>] command..."
33 # if no args specified, show usage
34 if [ $# -le 0 ]; then
35 echo $usage
36 exit 1
39 bin=`dirname "${BASH_SOURCE-$0}"`
40 bin=`cd "$bin">/dev/null; pwd`
42 . "$bin"/hbase-config.sh
44 if [ "$HBASE_MANAGES_ZK" = "" ]; then
45 HBASE_MANAGES_ZK=true
48 if [ "$HBASE_MANAGES_ZK" = "true" ]; then
49 hosts=`"$bin"/hbase org.apache.hadoop.hbase.zookeeper.ZKServerTool | grep '^ZK host:' | sed 's,^ZK host:,,'`
50 cmd=$"${@// /\\ }"
51 for zookeeper in $hosts; do
52 ssh $HBASE_SSH_OPTS $zookeeper $cmd 2>&1 | sed "s/^/$zookeeper: /" &
53 if [ "$HBASE_SLAVE_SLEEP" != "" ]; then
54 sleep $HBASE_SLAVE_SLEEP
56 done
59 wait