1#!/usr/bin/env bash
2
3#
4# Licensed to the Apache Software Foundation (ASF) under one or more
5# contributor license agreements.  See the NOTICE file distributed with
6# this work for additional information regarding copyright ownership.
7# The ASF licenses this file to You under the Apache License, Version 2.0
8# (the "License"); you may not use this file except in compliance with
9# the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19
20# Starts the master on the machine this script is executed on.
21
22if [ -z "${SPARK_HOME}" ]; then
23  export SPARK_HOME="$(cd "`dirname "$0"`"/..; pwd)"
24fi
25
26# NOTE: This exact class name is matched downstream by SparkSubmit.
27# Any changes need to be reflected there.
28CLASS="org.apache.spark.deploy.master.Master"
29
30if [[ "$@" = *--help ]] || [[ "$@" = *-h ]]; then
31  echo "Usage: ./sbin/start-master.sh [options]"
32  pattern="Usage:"
33  pattern+="\|Using Spark's default log4j profile:"
34  pattern+="\|Registered signal handlers for"
35
36  "${SPARK_HOME}"/bin/spark-class $CLASS --help 2>&1 | grep -v "$pattern" 1>&2
37  exit 1
38fi
39
40ORIGINAL_ARGS="$@"
41
42. "${SPARK_HOME}/sbin/spark-config.sh"
43
44. "${SPARK_HOME}/bin/load-spark-env.sh"
45
46if [ "$SPARK_MASTER_PORT" = "" ]; then
47  SPARK_MASTER_PORT=7077
48fi
49
50if [ "$SPARK_MASTER_HOST" = "" ]; then
51  case `uname` in
52      (SunOS)
53	  SPARK_MASTER_HOST="`/usr/sbin/check-hostname | awk '{print $NF}'`"
54	  ;;
55      (*)
56	  SPARK_MASTER_HOST="`hostname -f`"
57	  ;;
58  esac
59fi
60
61if [ "$SPARK_MASTER_WEBUI_PORT" = "" ]; then
62  SPARK_MASTER_WEBUI_PORT=8080
63fi
64
65"${SPARK_HOME}/sbin"/spark-daemon.sh start $CLASS 1 \
66  --host $SPARK_MASTER_HOST --port $SPARK_MASTER_PORT --webui-port $SPARK_MASTER_WEBUI_PORT \
67  $ORIGINAL_ARGS
68