Skip to content

Commit 94eb429

Browse files
authored
fix: spark-k8s graceful shutdown on SIGTERM (#1564)
* fix: spark-k8s graceful shutdown on SIGTERM * better formatting * fixing pre-commit hook false positive * fixing formatting * update changelog
1 parent dec24c1 commit 94eb429

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ All notable changes to this project will be documented in this file.
4040
- spark: bump hadoop `3.4.2` to `3.4.3` ([#1533])
4141
- hive: Bump `4.2.0` to Hadoop `3.4.3` ([#1539]).
4242
- java-devel: Bump Maven to 3.9.16 ([#1548]).
43+
- spark: fix graceful shutdown at SIGTERM ([#1564])
4344

4445
### Fixed
4546

@@ -95,6 +96,7 @@ All notable changes to this project will be documented in this file.
9596
[#1550]: https://github.com/stackabletech/docker-images/pull/1550
9697
[#1551]: https://github.com/stackabletech/docker-images/pull/1551
9798
[#1559]: https://github.com/stackabletech/docker-images/pull/1559
99+
[#1564]: https://github.com/stackabletech/docker-images/pull/1564
98100

99101
## [26.3.0] - 2026-03-16
100102

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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@
22

33
eval "$_STACKABLE_PRE_HOOK"
44

5-
/stackable/spark/kubernetes/dockerfiles/spark/entrypoint.sh "$@"
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=$!
8+
9+
# shellcheck disable=SC2329
10+
_handle_term() {
11+
kill -TERM "$child_pid" 2>/dev/null || true
12+
}
13+
trap _handle_term TERM INT
14+
15+
# `wait` returns immediately when the trap fires; loop until the child is actually gone.
16+
wait "$child_pid"
17+
while kill -0 "$child_pid" 2>/dev/null; do
18+
wait "$child_pid" 2>/dev/null || true
19+
done
620
result=$?
721

822
eval "$_STACKABLE_POST_HOOK"

0 commit comments

Comments
 (0)