forked from mziranhua/spark-init-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spark_master.sh
112 lines (83 loc) · 1.44 KB
/
spark_master.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
#!/bin/bash
SPARK_BASE_DIR=/usr/local/share/spark
SPARK_SBIN=$SPARK_BASE_DIR/sbin
PID=''
if [ -f $SPARK_BASE_DIR/conf/spark-env.sh ];then
source $SPARK_BASE_DIR/conf/spark-env.sh
else
echo "$SPARK_BASE_DIR/conf/spark-env.sh does not exist. Can't run script."
exit 1
fi
check_status() {
PID=$(ps ax | grep 'org.apache.spark.deploy.master.Master' | grep java | grep -v grep | awk '{print $1}')
if [ -n "$PID" ]
then
return 1
else
return 0
fi
}
start() {
check_status
if [ "$?" -ne 0 ]
then
echo "Master already running"
exit 1
fi
echo -n "Starting master ... "
runuser -c "$SPARK_SBIN/start-master.sh" spark &>/dev/null
sleep 5
check_status
if [ "$?" -eq 0 ]
then
echo "FAILURE"
exit 1
fi
echo "SUCCESS"
exit 0
}
stop() {
check_status
if [ "$?" -eq 0 ]
then
echo "No master running ..."
return 1
else
echo "Stopping master ..."
runuser -c "$SPARK_SBIN/stop-master.sh" spark &>/dev/null
sleep 4
echo "done"
return 0
fi
}
status() {
check_status
if [ "$?" -eq 0 ]
then
echo "No master running"
exit 1
else
echo -n "master running: "
echo $PID
exit 0
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0