2012-08-01 16:17:31 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2012-09-25 17:43:40 -04:00
|
|
|
#
|
2012-08-04 20:04:33 -04:00
|
|
|
# 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
|
|
|
|
#
|
2013-07-16 20:21:33 -04:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2012-08-04 20:04:33 -04:00
|
|
|
#
|
|
|
|
# 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.
|
2013-07-16 20:21:33 -04:00
|
|
|
#
|
2012-08-04 20:04:33 -04:00
|
|
|
|
2012-08-01 16:17:31 -04:00
|
|
|
# Run a shell command on all slave hosts.
|
|
|
|
#
|
|
|
|
# Environment Variables
|
|
|
|
#
|
|
|
|
# SPARK_SLAVES File naming remote hosts.
|
|
|
|
# Default is ${SPARK_CONF_DIR}/slaves.
|
|
|
|
# SPARK_CONF_DIR Alternate conf dir. Default is ${SPARK_HOME}/conf.
|
|
|
|
# SPARK_SLAVE_SLEEP Seconds to sleep between spawning remote commands.
|
|
|
|
# SPARK_SSH_OPTS Options passed to ssh when running remote commands.
|
|
|
|
##
|
|
|
|
|
2013-10-17 01:51:09 -04:00
|
|
|
usage="Usage: slaves.sh [--config <conf-dir>] command..."
|
2012-08-01 16:17:31 -04:00
|
|
|
|
|
|
|
# if no args specified, show usage
|
|
|
|
if [ $# -le 0 ]; then
|
|
|
|
echo $usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-09-08 13:24:15 -04:00
|
|
|
sbin="`dirname "$0"`"
|
|
|
|
sbin="`cd "$sbin"; pwd`"
|
2012-08-01 16:17:31 -04:00
|
|
|
|
2013-09-23 00:42:34 -04:00
|
|
|
. "$sbin/spark-config.sh"
|
2012-08-01 16:17:31 -04:00
|
|
|
|
|
|
|
# If the slaves file is specified in the command line,
|
2013-08-31 20:31:07 -04:00
|
|
|
# then it takes precedence over the definition in
|
2012-08-01 16:17:31 -04:00
|
|
|
# spark-env.sh. Save it here.
|
2014-09-25 19:49:15 -04:00
|
|
|
if [ -f "$SPARK_SLAVES" ]; then
|
|
|
|
HOSTLIST=`cat "$SPARK_SLAVES"`
|
|
|
|
fi
|
2012-08-01 16:17:31 -04:00
|
|
|
|
2013-10-17 01:51:09 -04:00
|
|
|
# Check if --config is passed as an argument. It is an optional parameter.
|
2013-10-17 01:55:15 -04:00
|
|
|
# Exit if the argument is not a directory.
|
2013-10-15 03:35:44 -04:00
|
|
|
if [ "$1" == "--config" ]
|
|
|
|
then
|
|
|
|
shift
|
2014-09-08 13:24:15 -04:00
|
|
|
conf_dir="$1"
|
2013-10-15 03:35:44 -04:00
|
|
|
if [ ! -d "$conf_dir" ]
|
|
|
|
then
|
2013-10-17 01:51:09 -04:00
|
|
|
echo "ERROR : $conf_dir is not a directory"
|
2013-10-15 03:35:44 -04:00
|
|
|
echo $usage
|
|
|
|
exit 1
|
|
|
|
else
|
2014-09-08 13:24:15 -04:00
|
|
|
export SPARK_CONF_DIR="$conf_dir"
|
2013-10-15 03:35:44 -04:00
|
|
|
fi
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2014-03-25 01:24:21 -04:00
|
|
|
. "$SPARK_PREFIX/bin/load-spark-env.sh"
|
2012-08-01 16:17:31 -04:00
|
|
|
|
|
|
|
if [ "$HOSTLIST" = "" ]; then
|
|
|
|
if [ "$SPARK_SLAVES" = "" ]; then
|
2014-09-25 19:49:15 -04:00
|
|
|
if [ -f "${SPARK_CONF_DIR}/slaves" ]; then
|
|
|
|
HOSTLIST=`cat "${SPARK_CONF_DIR}/slaves"`
|
|
|
|
else
|
|
|
|
HOSTLIST=localhost
|
|
|
|
fi
|
2012-08-01 16:17:31 -04:00
|
|
|
else
|
2014-09-25 19:49:15 -04:00
|
|
|
HOSTLIST=`cat "${SPARK_SLAVES}"`
|
2012-08-01 16:17:31 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2014-09-25 19:49:15 -04:00
|
|
|
|
|
|
|
|
2012-08-01 16:17:31 -04:00
|
|
|
# By default disable strict host key checking
|
|
|
|
if [ "$SPARK_SSH_OPTS" = "" ]; then
|
|
|
|
SPARK_SSH_OPTS="-o StrictHostKeyChecking=no"
|
|
|
|
fi
|
|
|
|
|
2014-09-25 19:49:15 -04:00
|
|
|
for slave in `echo "$HOSTLIST"|sed "s/#.*$//;/^$/d"`; do
|
|
|
|
if [ -n "${SPARK_SSH_FOREGROUND}" ]; then
|
|
|
|
ssh $SPARK_SSH_OPTS "$slave" $"${@// /\\ }" \
|
|
|
|
2>&1 | sed "s/^/$slave: /"
|
|
|
|
else
|
|
|
|
ssh $SPARK_SSH_OPTS "$slave" $"${@// /\\ }" \
|
|
|
|
2>&1 | sed "s/^/$slave: /" &
|
|
|
|
fi
|
|
|
|
if [ "$SPARK_SLAVE_SLEEP" != "" ]; then
|
|
|
|
sleep $SPARK_SLAVE_SLEEP
|
|
|
|
fi
|
2012-08-01 16:17:31 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
wait
|