forked from deanwampler/spark-scala-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·130 lines (114 loc) · 3.51 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
dir=$(dirname $0)
. $dir/scripts/find_cmds
help() {
cat <<EOF
usage: $0 [-h | --help] [act | activator | sbt ] [ui | shell] \
[--mem N] [-nq | --not-quiet] [options]
where:
-h | --help Print help and exit.
act | activator Use Activator (the default).
sbt Use SBT (command line interface).
ui | shell (Activator only) Use the Web UI (default) or the command line shell.
--mem N The default memory for Activator is 4096 (MB), which is also used
to run the non-Hadoop Spark examples. Use a larger integer value
N if you experience out of memory errors.
-nq|--not-quiet
By default, most Activator output is suppressed when the web UI is
used. For debugging purposes when running the web UI, use this
option to show this output.
options Any additional options to pass to Activator or SBT.
The default is Activator and the web-based UI.
EOF
}
filter_garbage() {
quiet=$1
while read line
do
if [[ ${line} =~ Please.point.your.browser.at ]] ; then
echo
echo "=================================================================="
echo
echo " Open your web browser to: http://$ip:9999"
echo
echo "=================================================================="
elif [[ ${line} =~ play.-.Application.started ]] ; then
echo $line
elif [[ -z $quiet ]] ; then
echo $line
fi
done
}
java_opts() {
mem=$1
perm=$(( $mem / 4 ))
(( $perm < 512 )) && perm=512
echo "-Xms${mem}M -Xmx${mem}M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=${perm}M"
}
mem=4096
quiet=yes
mode=ui
tool=activator
while [ $# -gt 0 ]
do
case $1 in
-h|--h*) help; exit 0 ;;
--mem) shift; mem=$1 ;;
-nq|--not-quiet) quiet= ;;
act*) tool=activator ;;
sbt*) tool=sbt; mode= ;;
ui|shell) mode=$1 ;;
*) break ;;
esac
shift
done
if [[ $tool = sbt && $mode = ui ]]
then
echo "$0: Can't specify 'sbt' and 'ui' together."
help
exit 1
fi
dir=$(dirname $0)
ip=$($dir/scripts/getip.sh)
act=
opts=()
msg=
if [[ $tool = activator ]]
then
act=$(find_activator "$HOME/activator/activator")
# Use http.address=0.0.0.0, because when running on a remote server,
# The Activator UI won't listen for remote connections otherwise.
# Invoke with NOOP=x start.sh to suppress execution:
opts=(-Dhttp.address=0.0.0.0 -Dhttp.port=9999 $mode)
umode=$(echo $mode | tr '[a-z]' '[A-Z]')
msg="Activator, using mode $umode"
else
act=$(find_sbt)
msg="SBT"
fi
if [[ -z $act ]]
then
echo "ERROR: Could not find $tool"
exit 1
fi
if [[ $mode = ui ]]
then
cat <<EOF
==================================================================
Starting the Spark Workshop in $msg
==================================================================
EOF
sleep 2
fi
log="$dir/$tool.log"
JAVA_OPTS=$(java_opts $mem)
if [[ $mode = ui ]]
then
echo "Running the Web UI. Writing all activity to $log"
echo running: JAVA_OPTS=\"$JAVA_OPTS\" "$act" "${opts[@]}"
[[ -z $NOOP ]] && ( JAVA_OPTS="$JAVA_OPTS" "$act" "${opts[@]}" 2>&1 | tee "$log" | filter_garbage $quiet )
else
echo "Running the command shell. Writing all activity to $log"
echo running: JAVA_OPTS=\"$JAVA_OPTS\" "$act" "${opts[@]}"
[[ -z $NOOP ]] && ( JAVA_OPTS="$JAVA_OPTS" "$act" "${opts[@]}" 2>&1 | tee "$log" )
fi