2013-07-17 20:51:18 -04:00
|
|
|
#!/usr/bin/env bash
|
2010-03-29 19:17:55 -04:00
|
|
|
|
2013-07-16 20:21: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
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# 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-22 16:11:35 -04:00
|
|
|
SCALA_VERSION=2.9.3
|
|
|
|
|
2010-03-29 19:17:55 -04:00
|
|
|
# Figure out where the Scala framework is installed
|
2010-10-16 15:18:02 -04:00
|
|
|
FWDIR="$(cd `dirname $0`; pwd)"
|
2010-03-29 19:17:55 -04:00
|
|
|
|
2010-10-15 22:42:26 -04:00
|
|
|
# Export this as SPARK_HOME
|
|
|
|
export SPARK_HOME="$FWDIR"
|
|
|
|
|
2010-07-19 21:00:30 -04:00
|
|
|
# Load environment variables from conf/spark-env.sh, if it exists
|
|
|
|
if [ -e $FWDIR/conf/spark-env.sh ] ; then
|
|
|
|
. $FWDIR/conf/spark-env.sh
|
|
|
|
fi
|
|
|
|
|
2013-02-06 17:34:46 -05:00
|
|
|
if [ -z "$1" ]; then
|
2013-09-01 19:45:57 -04:00
|
|
|
echo "Usage: spark-class <class> [<args>]" >&2
|
2013-02-06 17:34:46 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If this is a standalone cluster daemon, reset SPARK_JAVA_OPTS and SPARK_MEM to reasonable
|
|
|
|
# values for that; it doesn't need a lot
|
2013-09-20 22:27:08 -04:00
|
|
|
if [ "$1" = "org.apache.spark.deploy.master.Master" -o "$1" = "org.apache.spark.deploy.worker.Worker" ]; then
|
2013-02-06 17:34:46 -05:00
|
|
|
SPARK_MEM=${SPARK_DAEMON_MEMORY:-512m}
|
2013-05-11 01:42:22 -04:00
|
|
|
SPARK_DAEMON_JAVA_OPTS="$SPARK_DAEMON_JAVA_OPTS -Dspark.akka.logLifecycleEvents=true"
|
2013-02-24 15:24:30 -05:00
|
|
|
# Do not overwrite SPARK_JAVA_OPTS environment variable in this script
|
2013-06-25 15:47:40 -04:00
|
|
|
OUR_JAVA_OPTS="$SPARK_DAEMON_JAVA_OPTS" # Empty by default
|
2013-02-24 15:24:30 -05:00
|
|
|
else
|
2013-06-25 15:47:40 -04:00
|
|
|
OUR_JAVA_OPTS="$SPARK_JAVA_OPTS"
|
2013-02-06 17:34:46 -05:00
|
|
|
fi
|
|
|
|
|
2013-02-16 01:42:06 -05:00
|
|
|
|
|
|
|
# Add java opts for master, worker, executor. The opts maybe null
|
|
|
|
case "$1" in
|
2013-09-20 22:27:08 -04:00
|
|
|
'org.apache.spark.deploy.master.Master')
|
2013-06-25 15:47:40 -04:00
|
|
|
OUR_JAVA_OPTS="$OUR_JAVA_OPTS $SPARK_MASTER_OPTS"
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2013-09-20 22:27:08 -04:00
|
|
|
'org.apache.spark.deploy.worker.Worker')
|
2013-06-25 15:47:40 -04:00
|
|
|
OUR_JAVA_OPTS="$OUR_JAVA_OPTS $SPARK_WORKER_OPTS"
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2013-09-20 22:27:08 -04:00
|
|
|
'org.apache.spark.executor.StandaloneExecutorBackend')
|
2013-06-25 15:47:40 -04:00
|
|
|
OUR_JAVA_OPTS="$OUR_JAVA_OPTS $SPARK_EXECUTOR_OPTS"
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2013-09-20 22:27:08 -04:00
|
|
|
'org.apache.spark.executor.MesosExecutorBackend')
|
2013-06-25 15:47:40 -04:00
|
|
|
OUR_JAVA_OPTS="$OUR_JAVA_OPTS $SPARK_EXECUTOR_OPTS"
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2013-09-20 22:27:08 -04:00
|
|
|
'org.apache.spark.repl.Main')
|
2013-06-25 15:47:40 -04:00
|
|
|
OUR_JAVA_OPTS="$OUR_JAVA_OPTS $SPARK_REPL_OPTS"
|
2013-02-25 14:53:55 -05:00
|
|
|
;;
|
2013-02-16 01:42:06 -05:00
|
|
|
esac
|
|
|
|
|
2013-08-24 02:30:17 -04:00
|
|
|
# Find the java binary
|
|
|
|
if [ -n "${JAVA_HOME}" ]; then
|
|
|
|
RUNNER="${JAVA_HOME}/bin/java"
|
2012-10-22 16:10:47 -04:00
|
|
|
else
|
2013-08-24 02:30:17 -04:00
|
|
|
if [ `command -v java` ]; then
|
|
|
|
RUNNER="java"
|
2012-10-22 16:10:47 -04:00
|
|
|
else
|
2013-08-24 02:30:17 -04:00
|
|
|
echo "JAVA_HOME is not set" >&2
|
|
|
|
exit 1
|
2012-10-22 16:10:47 -04:00
|
|
|
fi
|
2013-08-24 02:30:17 -04:00
|
|
|
fi
|
2010-08-13 03:39:36 -04:00
|
|
|
|
2013-08-24 02:30:17 -04:00
|
|
|
# Set SPARK_MEM if it isn't already set since we also use it for this process
|
|
|
|
SPARK_MEM=${SPARK_MEM:-512m}
|
2012-03-17 16:39:14 -04:00
|
|
|
export SPARK_MEM
|
2010-07-19 21:00:30 -04:00
|
|
|
|
|
|
|
# Set JAVA_OPTS to be able to load native libraries and to set heap size
|
2013-02-24 15:24:30 -05:00
|
|
|
JAVA_OPTS="$OUR_JAVA_OPTS"
|
2013-05-11 01:42:22 -04:00
|
|
|
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=$SPARK_LIBRARY_PATH"
|
|
|
|
JAVA_OPTS="$JAVA_OPTS -Xms$SPARK_MEM -Xmx$SPARK_MEM"
|
2010-07-19 21:00:30 -04:00
|
|
|
# Load extra JAVA_OPTS from conf/java-opts, if it exists
|
2010-03-29 19:17:55 -04:00
|
|
|
if [ -e $FWDIR/conf/java-opts ] ; then
|
2013-05-11 01:42:22 -04:00
|
|
|
JAVA_OPTS="$JAVA_OPTS `cat $FWDIR/conf/java-opts`"
|
2010-03-29 19:17:55 -04:00
|
|
|
fi
|
|
|
|
export JAVA_OPTS
|
2013-02-15 08:11:34 -05:00
|
|
|
# Attention: when changing the way the JAVA_OPTS are assembled, the change must be reflected in ExecutorRunner.scala!
|
2010-03-29 19:17:55 -04:00
|
|
|
|
2013-06-28 20:18:35 -04:00
|
|
|
if [ ! -f "$FWDIR/RELEASE" ]; then
|
|
|
|
# Exit if the user hasn't compiled Spark
|
2013-08-30 15:38:23 -04:00
|
|
|
ls "$FWDIR"/assembly/target/scala-$SCALA_VERSION/spark-assembly*hadoop*.jar >& /dev/null
|
2013-08-24 02:30:17 -04:00
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
echo "Failed to find Spark assembly in $FWDIR/assembly/target" >&2
|
2013-08-30 15:38:23 -04:00
|
|
|
echo "You need to build Spark with sbt/sbt assembly before running this program" >&2
|
2013-06-28 20:18:35 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
2013-05-16 17:31:38 -04:00
|
|
|
fi
|
|
|
|
|
2013-06-25 18:21:00 -04:00
|
|
|
# Compute classpath using external script
|
|
|
|
CLASSPATH=`$FWDIR/bin/compute-classpath.sh`
|
|
|
|
export CLASSPATH
|
2010-03-29 19:17:55 -04:00
|
|
|
|
2013-08-02 19:58:19 -04:00
|
|
|
if [ "$SPARK_PRINT_LAUNCH_COMMAND" == "1" ]; then
|
2013-08-24 02:30:17 -04:00
|
|
|
echo -n "Spark Command: "
|
|
|
|
echo "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@"
|
2013-08-04 00:30:15 -04:00
|
|
|
echo "========================================"
|
2013-08-02 19:58:19 -04:00
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
2013-08-24 02:30:17 -04:00
|
|
|
exec "$RUNNER" -cp "$CLASSPATH" $JAVA_OPTS "$@"
|