Skip to content

Commit 7266790

Browse files
committed
fix: spark-k8s graceful shutdown on SIGTERM
1 parent 46ad345 commit 7266790

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

spark-k8s/Dockerfile.3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,4 @@ EOF
258258
USER ${STACKABLE_USER_UID}
259259

260260
WORKDIR ${SPARK_HOME}
261-
ENTRYPOINT [ "/stackable/run-spark.sh" ]
261+
ENTRYPOINT [ "/usr/bin/tini", "-s", "--", "/stackable/run-spark.sh" ]

spark-k8s/Dockerfile.4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,4 @@ EOF
230230
USER ${STACKABLE_USER_UID}
231231

232232
WORKDIR ${SPARK_HOME}
233-
ENTRYPOINT [ "/stackable/run-spark.sh" ]
233+
ENTRYPOINT [ "/usr/bin/tini", "-s", "--", "/stackable/run-spark.sh" ]

spark-k8s/stackable/run-spark.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
#!/bin/bash
22

3-
eval "$_STACKABLE_PRE_HOOK"
3+
eval "$_STACKABLE_PRE_HOOK"
44

5-
/stackable/spark/kubernetes/dockerfiles/spark/entrypoint.sh "$@"
6-
result=$?
5+
# Forward SIGTERM to the Spark entrypoint to support spark JVM's gracefully shutdown.
6+
/stackable/spark/kubernetes/dockerfiles/spark/entrypoint.sh "$@" &
7+
child_pid=$!
78

8-
eval "$_STACKABLE_POST_HOOK"
9+
_handle_term() {
10+
kill -TERM "$child_pid" 2>/dev/null || true
11+
}
12+
trap _handle_term TERM INT
913

10-
exit $result
14+
# `wait` returns immediately when the trap fires; loop until the child is actually gone.
15+
wait "$child_pid"
16+
while kill -0 "$child_pid" 2>/dev/null; do
17+
wait "$child_pid" 2>/dev/null || true
18+
done
19+
result=$?
20+
21+
eval "$_STACKABLE_POST_HOOK"
22+
23+
exit $result

0 commit comments

Comments
 (0)