From b4905c383bf24143966d8b2d0ae69ef9ee7c3b0e Mon Sep 17 00:00:00 2001 From: Patrick Wendell Date: Fri, 2 Aug 2013 16:58:19 -0700 Subject: Log the launch command for Spark daemons For debugging and analysis purposes, it's nice to have the exact command used to launch Spark contained within the logs. This adds the necessary hooks to make that possible. --- bin/spark-daemon.sh | 5 ++++- run | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/spark-daemon.sh b/bin/spark-daemon.sh index a5b88ca785..96c71e66ca 100755 --- a/bin/spark-daemon.sh +++ b/bin/spark-daemon.sh @@ -75,6 +75,8 @@ if [ "$SPARK_IDENT_STRING" = "" ]; then export SPARK_IDENT_STRING="$USER" fi +export SPARK_PRINT_LAUNCH_COMMAND="1" + # get log directory if [ "$SPARK_LOG_DIR" = "" ]; then export SPARK_LOG_DIR="$SPARK_HOME/logs" @@ -124,8 +126,9 @@ case $startStop in spark_rotate_log $log echo starting $command, logging to $log + echo "Spark Daemon: $command" > $log cd "$SPARK_PREFIX" - nohup nice -n $SPARK_NICENESS "$SPARK_PREFIX"/run $command "$@" > "$log" 2>&1 < /dev/null & + nohup nice -n $SPARK_NICENESS "$SPARK_PREFIX"/run $command "$@" >> "$log" 2>&1 < /dev/null & echo $! > $pid sleep 1; head "$log" ;; diff --git a/run b/run index 0a440627a1..8bbde1a027 100755 --- a/run +++ b/run @@ -164,4 +164,12 @@ else # The JVM doesn't read JAVA_OPTS by default so we need to pass it in EXTRA_ARGS="$JAVA_OPTS" fi -exec "$RUNNER" -cp "$CLASSPATH" $EXTRA_ARGS "$@" + +command="$RUNNER -cp \"$CLASSPATH\" $EXTRA_ARGS $@" +if [ "$SPARK_PRINT_LAUNCH_COMMAND" == "1" ]; then + echo "Spark Command: $command" + echo "======================================" + echo +fi + +exec $command -- cgit v1.2.3 From ad94fbb3221fb50a613cdcaf1c8d8f08b45f4064 Mon Sep 17 00:00:00 2001 From: Patrick Wendell Date: Sat, 3 Aug 2013 09:19:46 -0700 Subject: Log the launch command for Spark executors --- .../main/scala/spark/deploy/worker/ExecutorRunner.scala | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala b/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala index 345dfe879c..1dcdf20960 100644 --- a/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala +++ b/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala @@ -22,6 +22,9 @@ import java.lang.System.getenv import akka.actor.ActorRef +import com.google.common.base.Charsets +import com.google.common.io.Files + import spark.{Utils, Logging} import spark.deploy.{ExecutorState, ApplicationDescription} import spark.deploy.DeployMessages.ExecutorStateChanged @@ -125,7 +128,7 @@ private[spark] class ExecutorRunner( /** Spawn a thread that will redirect a given stream to a file */ def redirectStream(in: InputStream, file: File) { - val out = new FileOutputStream(file) + val out = new FileOutputStream(file, true) new Thread("redirect output to " + file) { override def run() { try { @@ -161,9 +164,16 @@ private[spark] class ExecutorRunner( env.put("SPARK_LAUNCH_WITH_SCALA", "0") process = builder.start() + val header = "Spark Executor Command: %s\n======================================\n\n" + .format(command.mkString(" ")) + // Redirect its stdout and stderr to files - redirectStream(process.getInputStream, new File(executorDir, "stdout")) - redirectStream(process.getErrorStream, new File(executorDir, "stderr")) + val stdout = new File(executorDir, "stdout") + Files.write(header, stdout, Charsets.UTF_8) + redirectStream(process.getInputStream, stdout) + + val stderr = new File(executorDir, "stderr") + redirectStream(process.getErrorStream, stderr) // Wait for it to exit; this is actually a bad thing if it happens, because we expect to run // long-lived processes only. However, in the future, we might restart the executor a few -- cgit v1.2.3 From f3660d5ab8d3f3b48dda60dc7daf02affd5cc664 Mon Sep 17 00:00:00 2001 From: Patrick Wendell Date: Sat, 3 Aug 2013 21:30:15 -0700 Subject: Make output formatting consistent between bash/scala --- core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala | 3 +-- run | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala b/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala index 1dcdf20960..88c5b5bbd6 100644 --- a/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala +++ b/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala @@ -164,8 +164,7 @@ private[spark] class ExecutorRunner( env.put("SPARK_LAUNCH_WITH_SCALA", "0") process = builder.start() - val header = "Spark Executor Command: %s\n======================================\n\n" - .format(command.mkString(" ")) + val header = "Spark Executor Command: %s\n%s\n\n".format(command.mkString(" "), "=" * 40) // Redirect its stdout and stderr to files val stdout = new File(executorDir, "stdout") diff --git a/run b/run index 8bbde1a027..3868332c90 100755 --- a/run +++ b/run @@ -168,7 +168,7 @@ fi command="$RUNNER -cp \"$CLASSPATH\" $EXTRA_ARGS $@" if [ "$SPARK_PRINT_LAUNCH_COMMAND" == "1" ]; then echo "Spark Command: $command" - echo "======================================" + echo "========================================" echo fi -- cgit v1.2.3 From 3970b580c206d58189ade3930aca1e478bff8c84 Mon Sep 17 00:00:00 2001 From: Patrick Wendell Date: Sun, 4 Aug 2013 16:55:18 -0700 Subject: Using quotes when printing out command --- core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala b/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala index 88c5b5bbd6..7423eca11e 100644 --- a/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala +++ b/core/src/main/scala/spark/deploy/worker/ExecutorRunner.scala @@ -164,7 +164,8 @@ private[spark] class ExecutorRunner( env.put("SPARK_LAUNCH_WITH_SCALA", "0") process = builder.start() - val header = "Spark Executor Command: %s\n%s\n\n".format(command.mkString(" "), "=" * 40) + val header = "Spark Executor Command: %s\n%s\n\n".format( + command.mkString("\"", "\" \"", "\""), "=" * 40) // Redirect its stdout and stderr to files val stdout = new File(executorDir, "stdout") -- cgit v1.2.3