2727# SPARK_PID_DIR The pid files are stored. /tmp by default.
2828# SPARK_IDENT_STRING A string representing this instance of spark. $USER by default
2929# SPARK_NICENESS The scheduling priority for daemons. Defaults to 0.
30+ # SPARK_NO_DAEMONIZE If set, will run the proposed command in the foreground. It will not output a PID file.
3031# #
3132
3233usage=" Usage: spark-daemon.sh [--config <conf-dir>] (start|stop|submit|status) <spark-command> <spark-instance-number> <args...>"
@@ -122,6 +123,35 @@ if [ "$SPARK_NICENESS" = "" ]; then
122123 export SPARK_NICENESS=0
123124fi
124125
126+ execute_command () {
127+ command=" $@ "
128+ if [ " $SPARK_NO_DAEMONIZE " != " " ]; then
129+ eval $command
130+ else
131+ eval " nohup $command >> \" $log \" 2>&1 < /dev/null &"
132+ newpid=" $! "
133+
134+ echo " $newpid " > " $pid "
135+
136+ # Poll for up to 5 seconds for the java process to start
137+ for i in {1..10}
138+ do
139+ if [[ $( ps -p " $newpid " -o comm=) =~ " java" ]]; then
140+ break
141+ fi
142+ sleep 0.5
143+ done
144+
145+ sleep 2
146+ # Check if the process has died; in that case we'll tail the log so the user can see
147+ if [[ ! $( ps -p " $newpid " -o comm=) =~ " java" ]]; then
148+ echo " failed to launch $command :"
149+ tail -2 " $log " | sed ' s/^/ /'
150+ echo " full log in $log "
151+ fi
152+ fi
153+ }
154+
125155run_command () {
126156 mode=" $1 "
127157 shift
@@ -146,13 +176,11 @@ run_command() {
146176
147177 case " $mode " in
148178 (class)
149- nohup nice -n " $SPARK_NICENESS " " ${SPARK_HOME} " /bin/spark-class $command " $@ " >> " $log " 2>&1 < /dev/null &
150- newpid=" $! "
179+ execute_command " nice -n \" $SPARK_NICENESS \" \" ${SPARK_HOME} /bin/spark-class\" $command $@ "
151180 ;;
152181
153182 (submit)
154- nohup nice -n " $SPARK_NICENESS " " ${SPARK_HOME} " /bin/spark-submit --class $command " $@ " >> " $log " 2>&1 < /dev/null &
155- newpid=" $! "
183+ execute_command " nice -n \" $SPARK_NICENESS \" \" ${SPARK_HOME} /bin/spark-submit\" --class $command $@ "
156184 ;;
157185
158186 (* )
@@ -161,24 +189,6 @@ run_command() {
161189 ;;
162190 esac
163191
164- echo " $newpid " > " $pid "
165-
166- # Poll for up to 5 seconds for the java process to start
167- for i in {1..10}
168- do
169- if [[ $( ps -p " $newpid " -o comm=) =~ " java" ]]; then
170- break
171- fi
172- sleep 0.5
173- done
174-
175- sleep 2
176- # Check if the process has died; in that case we'll tail the log so the user can see
177- if [[ ! $( ps -p " $newpid " -o comm=) =~ " java" ]]; then
178- echo " failed to launch $command :"
179- tail -2 " $log " | sed ' s/^/ /'
180- echo " full log in $log "
181- fi
182192}
183193
184194case $option in
0 commit comments