[66] | 1 | #!/usr/bin/env bash |
---|
| 2 | |
---|
| 3 | # Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 4 | # contributor license agreements. See the NOTICE file distributed with |
---|
| 5 | # this work for additional information regarding copyright ownership. |
---|
| 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 7 | # (the "License"); you may not use this file except in compliance with |
---|
| 8 | # the License. You may obtain a copy of the License at |
---|
| 9 | # |
---|
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | # |
---|
| 12 | # Unless required by applicable law or agreed to in writing, software |
---|
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 15 | # See the License for the specific language governing permissions and |
---|
| 16 | # limitations under the License. |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | # Run a shell command on all slave hosts. |
---|
| 20 | # |
---|
| 21 | # Environment Variables |
---|
| 22 | # |
---|
| 23 | # HADOOP_SLAVES File naming remote hosts. |
---|
| 24 | # Default is ${HADOOP_CONF_DIR}/slaves. |
---|
| 25 | # HADOOP_CONF_DIR Alternate conf dir. Default is ${HADOOP_HOME}/conf. |
---|
| 26 | # HADOOP_SLAVE_SLEEP Seconds to sleep between spawning remote commands. |
---|
| 27 | # HADOOP_SSH_OPTS Options passed to ssh when running remote commands. |
---|
| 28 | ## |
---|
| 29 | |
---|
| 30 | usage="Usage: slaves.sh [--config confdir] command..." |
---|
| 31 | |
---|
| 32 | # if no args specified, show usage |
---|
| 33 | if [ $# -le 0 ]; then |
---|
| 34 | echo $usage |
---|
| 35 | exit 1 |
---|
| 36 | fi |
---|
| 37 | |
---|
| 38 | bin=`dirname "$0"` |
---|
| 39 | bin=`cd "$bin"; pwd` |
---|
| 40 | |
---|
| 41 | . "$bin"/hadoop-config.sh |
---|
| 42 | |
---|
| 43 | # If the slaves file is specified in the command line, |
---|
| 44 | # then it takes precedence over the definition in |
---|
| 45 | # hadoop-env.sh. Save it here. |
---|
| 46 | HOSTLIST=$HADOOP_SLAVES |
---|
| 47 | |
---|
| 48 | if [ -f "${HADOOP_CONF_DIR}/hadoop-env.sh" ]; then |
---|
| 49 | . "${HADOOP_CONF_DIR}/hadoop-env.sh" |
---|
| 50 | fi |
---|
| 51 | |
---|
| 52 | if [ "$HOSTLIST" = "" ]; then |
---|
| 53 | if [ "$HADOOP_SLAVES" = "" ]; then |
---|
| 54 | export HOSTLIST="${HADOOP_CONF_DIR}/slaves" |
---|
| 55 | else |
---|
| 56 | export HOSTLIST="${HADOOP_SLAVES}" |
---|
| 57 | fi |
---|
| 58 | fi |
---|
| 59 | |
---|
| 60 | for slave in `cat "$HOSTLIST"`; do |
---|
| 61 | ssh $HADOOP_SSH_OPTS $slave $"${@// /\\ }" \ |
---|
| 62 | 2>&1 | sed "s/^/$slave: /" & |
---|
| 63 | if [ "$HADOOP_SLAVE_SLEEP" != "" ]; then |
---|
| 64 | sleep $HADOOP_SLAVE_SLEEP |
---|
| 65 | fi |
---|
| 66 | done |
---|
| 67 | |
---|
| 68 | wait |
---|