1
0

slaves.sh 2.0 KB

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