From f70555ed00739ba98fb476eea79dd276d4755eec Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Wed, 16 Oct 2024 12:53:25 +0200 Subject: [PATCH 01/10] feat(hbase): provision hbase-entrypoint.sh --- hbase/Dockerfile | 3 +- hbase/stackable/bin/hbase-entrypoint.sh | 61 +++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 hbase/stackable/bin/hbase-entrypoint.sh diff --git a/hbase/Dockerfile b/hbase/Dockerfile index 31e5cc478..899ae6821 100644 --- a/hbase/Dockerfile +++ b/hbase/Dockerfile @@ -318,6 +318,7 @@ COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-builder /stackable/jmx /stacka COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-operator-tools-builder /stackable/hbase-operator-tools-${HBASE_OPERATOR_TOOLS} /stackable/hbase-operator-tools-${HBASE_OPERATOR_TOOLS}/ COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-operator-tools-builder /stackable/bin/hbck2 /stackable/bin/hbck2 +COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-operator-tools-builder /stackable/bin/hbase-entrypoint.sh /stackable/hbase-${PRODUCT}/bin/hbase-entrypoint.sh COPY --chown=${STACKABLE_USER_UID}:0 --from=phoenix-builder /stackable/phoenix /stackable/phoenix/ @@ -367,4 +368,4 @@ ENV PATH="${PATH}:/stackable/bin:/stackable/hbase/bin" ENV ASYNC_PROFILER_HOME=/stackable/async-profiler WORKDIR /stackable/hbase -CMD ["./bin/hbase", "master", "start" ] +CMD ["./bin/hbase-entrypoint", "master", "localhost", "16010" ] diff --git a/hbase/stackable/bin/hbase-entrypoint.sh b/hbase/stackable/bin/hbase-entrypoint.sh new file mode 100644 index 000000000..98be357ab --- /dev/null +++ b/hbase/stackable/bin/hbase-entrypoint.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# +# Entrypoint for HBase that ensures services are shutdown gracefuly +# +set -x +set -euo pipefail + +HBASE_ROLE_NAME="$1" +HBASE_ROLE_SERVICE_NAME="$2" +HBASE_ROLE_SERVICE_PORT="$3" + +# TODO: remove hard coded svc.cluster.local +HBASE_ROLE_SERVICE_HOST="${HOSTNAME}.${HBASE_ROLE_SERVICE_NAME}.${NAMESPACE}.svc.cluster.local" + +REGION_MOVER_OPTS="--regionserverhost ${HBASE_ROLE_SERVICE_HOST}:${HBASE_ROLE_SERVICE_PORT} --operation unload ${REGION_MOVER_OPTS}" + +prepare_signal_handlers() { + unset term_child_pid + unset term_kill_needed + trap handle_term_signal TERM +} + +handle_term_signal() { + if [ "${term_child_pid}" ]; then + if [ "regionserver" == "${HBASE_ROLE_NAME}" ]; then + echo "Running pre-shutdown command: /stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover ${REGION_MOVER_OPTS}" + /stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover "${REGION_MOVER_OPTS}" + echo "Done pre-shutdown command" + fi + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed='yes' + fi +} + +wait_for_termination() { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait "${term_child_pid}" 2>/dev/null + trap - TERM + wait "${term_child_pid}" 2>/dev/null + set -e +} + +# ################################################################################################## +# main +# ################################################################################################## +mkdir -p /stackable/conf +cp /stackable/tmp/hdfs/hdfs-site.xml /stackable/conf +cp /stackable/tmp/hdfs/core-site.xml /stackable/conf +cp /stackable/tmp/hbase/* /stackable/conf +cp /stackable/tmp/log_config/log4j.properties /stackable/conf + +rm -f /stackable/log/_vector/shutdown +prepare_signal_handlers +/stackable/hbase/bin/hbase "${HBASE_ROLE_NAME}" start & +wait_for_termination $! +mkdir -p /stackable/log/_vector && touch /stackable/log/_vector/shutdown From a60fef68df9788a9e9fa92648077f96938f46c77 Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:28:50 +0200 Subject: [PATCH 02/10] Dockerfile.entrypoint --- hbase/Dockerfile.entrypoint | 3 +++ hbase/stackable/bin/hbase-entrypoint.sh | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 hbase/Dockerfile.entrypoint diff --git a/hbase/Dockerfile.entrypoint b/hbase/Dockerfile.entrypoint new file mode 100644 index 000000000..3a9496b70 --- /dev/null +++ b/hbase/Dockerfile.entrypoint @@ -0,0 +1,3 @@ +FROM docker.stackable.tech/stackable/hbase:2.6.0-stackable0.0.0-dev + +COPY --chown=1000:0 --chmod=755 hbase/stackable/bin/hbase-entrypoint.sh /stackable/hbase-2.6.0/bin/hbase-entrypoint.sh diff --git a/hbase/stackable/bin/hbase-entrypoint.sh b/hbase/stackable/bin/hbase-entrypoint.sh index 98be357ab..c1c7f0b4d 100644 --- a/hbase/stackable/bin/hbase-entrypoint.sh +++ b/hbase/stackable/bin/hbase-entrypoint.sh @@ -5,8 +5,11 @@ set -x set -euo pipefail +# master, regionserver, rest HBASE_ROLE_NAME="$1" +# k8s service name for this role+group combo HBASE_ROLE_SERVICE_NAME="$2" +# 16010 for master, 16020 for regionservers etc. HBASE_ROLE_SERVICE_PORT="$3" # TODO: remove hard coded svc.cluster.local From 989a7a90b98b7325c359934230567b7f78607edc Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:56:30 +0200 Subject: [PATCH 03/10] working version of hbase-entrypoint.sh --- hbase/stackable/bin/hbase-entrypoint.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hbase/stackable/bin/hbase-entrypoint.sh b/hbase/stackable/bin/hbase-entrypoint.sh index c1c7f0b4d..1e1c0a15b 100644 --- a/hbase/stackable/bin/hbase-entrypoint.sh +++ b/hbase/stackable/bin/hbase-entrypoint.sh @@ -27,7 +27,10 @@ handle_term_signal() { if [ "${term_child_pid}" ]; then if [ "regionserver" == "${HBASE_ROLE_NAME}" ]; then echo "Running pre-shutdown command: /stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover ${REGION_MOVER_OPTS}" - /stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover "${REGION_MOVER_OPTS}" + # REGION_MOVER_OPTS is a string that contains multiple arguments and needs to be spliced here + # therefore disable shellcheck for this line + # shellcheck disable=SC2086 + /stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover ${REGION_MOVER_OPTS} echo "Done pre-shutdown command" fi kill -TERM "${term_child_pid}" 2>/dev/null @@ -55,7 +58,7 @@ mkdir -p /stackable/conf cp /stackable/tmp/hdfs/hdfs-site.xml /stackable/conf cp /stackable/tmp/hdfs/core-site.xml /stackable/conf cp /stackable/tmp/hbase/* /stackable/conf -cp /stackable/tmp/log_config/log4j.properties /stackable/conf +cp /stackable/tmp/log_config/log4j* /stackable/conf rm -f /stackable/log/_vector/shutdown prepare_signal_handlers From 566123ec4ec607e08a458c21907cb8bd6cc6ad4b Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:58:31 +0200 Subject: [PATCH 04/10] hbase-entrypoint.sh: update script args --- hbase/stackable/bin/hbase-entrypoint.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hbase/stackable/bin/hbase-entrypoint.sh b/hbase/stackable/bin/hbase-entrypoint.sh index 1e1c0a15b..5da0c6104 100644 --- a/hbase/stackable/bin/hbase-entrypoint.sh +++ b/hbase/stackable/bin/hbase-entrypoint.sh @@ -8,15 +8,20 @@ set -euo pipefail # master, regionserver, rest HBASE_ROLE_NAME="$1" # k8s service name for this role+group combo +# ..svc.cluster.local HBASE_ROLE_SERVICE_NAME="$2" # 16010 for master, 16020 for regionservers etc. HBASE_ROLE_SERVICE_PORT="$3" -# TODO: remove hard coded svc.cluster.local -HBASE_ROLE_SERVICE_HOST="${HOSTNAME}.${HBASE_ROLE_SERVICE_NAME}.${NAMESPACE}.svc.cluster.local" +HBASE_ROLE_SERVICE_HOST="${HOSTNAME}.${HBASE_ROLE_SERVICE_NAME}" REGION_MOVER_OPTS="--regionserverhost ${HBASE_ROLE_SERVICE_HOST}:${HBASE_ROLE_SERVICE_PORT} --operation unload ${REGION_MOVER_OPTS}" +if [ -f /stackable/kerberos/krb5.conf ]; then + KERBEROS_REALM=$(grep -oP 'default_realm = \\K.*' /stackable/kerberos/krb5.conf) + export KERBEROS_REALM +fi + prepare_signal_handlers() { unset term_child_pid unset term_kill_needed @@ -26,12 +31,12 @@ prepare_signal_handlers() { handle_term_signal() { if [ "${term_child_pid}" ]; then if [ "regionserver" == "${HBASE_ROLE_NAME}" ]; then - echo "Running pre-shutdown command: /stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover ${REGION_MOVER_OPTS}" + echo "Start pre-shutdown" # REGION_MOVER_OPTS is a string that contains multiple arguments and needs to be spliced here # therefore disable shellcheck for this line # shellcheck disable=SC2086 /stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover ${REGION_MOVER_OPTS} - echo "Done pre-shutdown command" + echo "Done pre-shutdown" fi kill -TERM "${term_child_pid}" 2>/dev/null else From b0e0931ff85a63df50f58116208bd30442810d18 Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:52:53 +0200 Subject: [PATCH 05/10] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d204cc377..405ab8204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. the Azure Data Lake Storage ([#853]). - kafka: Add cyrus-sasl-gssapi package for kerberos ([#874]). - spark: Add HBase connector ([#878], [#882]). +- hbase: hbase-entrypoint.sh script to start and gracefully stop services ([#899]). ### Changed @@ -85,6 +86,7 @@ All notable changes to this project will be documented in this file. [#890]: https://github.com/stackabletech/docker-images/pull/890 [#894]: https://github.com/stackabletech/docker-images/pull/894 [#896]: https://github.com/stackabletech/docker-images/pull/896 +[#899]: https://github.com/stackabletech/docker-images/pull/899 ## [24.7.0] - 2024-07-24 From 88ed0cef1996f3c3725c0c16bab89cbf904c20af Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:53:30 +0200 Subject: [PATCH 06/10] changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 405ab8204..98730f186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file. the Azure Data Lake Storage ([#853]). - kafka: Add cyrus-sasl-gssapi package for kerberos ([#874]). - spark: Add HBase connector ([#878], [#882]). -- hbase: hbase-entrypoint.sh script to start and gracefully stop services ([#899]). +- hbase: hbase-entrypoint.sh script to start and gracefully stop services ([#898]). ### Changed @@ -86,7 +86,7 @@ All notable changes to this project will be documented in this file. [#890]: https://github.com/stackabletech/docker-images/pull/890 [#894]: https://github.com/stackabletech/docker-images/pull/894 [#896]: https://github.com/stackabletech/docker-images/pull/896 -[#899]: https://github.com/stackabletech/docker-images/pull/899 +[#898]: https://github.com/stackabletech/docker-images/pull/898 ## [24.7.0] - 2024-07-24 From 9951fc8db5b9730e35ce650ecf584d2fcab7c48e Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:56:38 +0300 Subject: [PATCH 07/10] Delete hbase/Dockerfile.entrypoint --- hbase/Dockerfile.entrypoint | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 hbase/Dockerfile.entrypoint diff --git a/hbase/Dockerfile.entrypoint b/hbase/Dockerfile.entrypoint deleted file mode 100644 index 3a9496b70..000000000 --- a/hbase/Dockerfile.entrypoint +++ /dev/null @@ -1,3 +0,0 @@ -FROM docker.stackable.tech/stackable/hbase:2.6.0-stackable0.0.0-dev - -COPY --chown=1000:0 --chmod=755 hbase/stackable/bin/hbase-entrypoint.sh /stackable/hbase-2.6.0/bin/hbase-entrypoint.sh From d9a7f470c07432ef5f2875d9432526b8c09dbd6c Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:04:01 +0200 Subject: [PATCH 08/10] fix missing file in previous stage --- hbase/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/hbase/Dockerfile b/hbase/Dockerfile index 98da8fde2..d72343144 100644 --- a/hbase/Dockerfile +++ b/hbase/Dockerfile @@ -140,6 +140,7 @@ ARG DELETE_CACHES="true" # does not work, so please ignore the according warning (SC2016). COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/bin/hbck2.env /stackable/bin/ COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/patches /stackable/patches +COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/bin/hbase-entrypoint.sh /stackable/bin/ USER ${STACKABLE_USER_UID} WORKDIR /stackable From 521fc62fe9d76a0438ef981136ce3fafd5a5a82d Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:20:31 +0200 Subject: [PATCH 09/10] optionally run region mover --- hbase/stackable/bin/hbase-entrypoint.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hbase/stackable/bin/hbase-entrypoint.sh b/hbase/stackable/bin/hbase-entrypoint.sh index 5da0c6104..67d0d82b7 100644 --- a/hbase/stackable/bin/hbase-entrypoint.sh +++ b/hbase/stackable/bin/hbase-entrypoint.sh @@ -2,6 +2,10 @@ # # Entrypoint for HBase that ensures services are shutdown gracefuly # +# Expects the following env vars: +# - RUN_REGION_MOVER: if set to true, the region mover will be run before region server shutdown +# - REGION_MOVER_OPTS: additional options for the region mover +# set -x set -euo pipefail @@ -30,7 +34,7 @@ prepare_signal_handlers() { handle_term_signal() { if [ "${term_child_pid}" ]; then - if [ "regionserver" == "${HBASE_ROLE_NAME}" ]; then + if [ "regionserver" == "${HBASE_ROLE_NAME}" ] && [ "true" == "${RUN_REGION_MOVER}" ]; then echo "Start pre-shutdown" # REGION_MOVER_OPTS is a string that contains multiple arguments and needs to be spliced here # therefore disable shellcheck for this line From 8dc3fddf0ea382ecd33f43496a5c08fef4314262 Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:43:42 +0200 Subject: [PATCH 10/10] fix krb realm regex --- hbase/stackable/bin/hbase-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hbase/stackable/bin/hbase-entrypoint.sh b/hbase/stackable/bin/hbase-entrypoint.sh index 67d0d82b7..89b488a21 100644 --- a/hbase/stackable/bin/hbase-entrypoint.sh +++ b/hbase/stackable/bin/hbase-entrypoint.sh @@ -22,7 +22,7 @@ HBASE_ROLE_SERVICE_HOST="${HOSTNAME}.${HBASE_ROLE_SERVICE_NAME}" REGION_MOVER_OPTS="--regionserverhost ${HBASE_ROLE_SERVICE_HOST}:${HBASE_ROLE_SERVICE_PORT} --operation unload ${REGION_MOVER_OPTS}" if [ -f /stackable/kerberos/krb5.conf ]; then - KERBEROS_REALM=$(grep -oP 'default_realm = \\K.*' /stackable/kerberos/krb5.conf) + KERBEROS_REALM=$(grep -oP 'default_realm = \K.*' /stackable/kerberos/krb5.conf) export KERBEROS_REALM fi