Skip to content

Commit dff82c6

Browse files
razvanNickLarsenNZ
andauthored
feat(hbase): add hbase-entrypoint.sh script (#898)
* feat(hbase): provision hbase-entrypoint.sh * Dockerfile.entrypoint * working version of hbase-entrypoint.sh * hbase-entrypoint.sh: update script args * changelog * changelog * Delete hbase/Dockerfile.entrypoint * fix missing file in previous stage * optionally run region mover * fix krb realm regex --------- Co-authored-by: Nick <[email protected]>
1 parent 2a4fc6f commit dff82c6

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
2222
the Azure Data Lake Storage ([#853]).
2323
- kafka: Add cyrus-sasl-gssapi package for kerberos ([#874]).
2424
- spark: Add HBase connector ([#878], [#882]).
25+
- hbase: hbase-entrypoint.sh script to start and gracefully stop services ([#898]).
2526

2627
### Changed
2728

@@ -86,6 +87,7 @@ All notable changes to this project will be documented in this file.
8687
[#890]: https://github.com/stackabletech/docker-images/pull/890
8788
[#894]: https://github.com/stackabletech/docker-images/pull/894
8889
[#896]: https://github.com/stackabletech/docker-images/pull/896
90+
[#898]: https://github.com/stackabletech/docker-images/pull/898
8991
[#901]: https://github.com/stackabletech/docker-images/pull/901
9092
[#903]: https://github.com/stackabletech/docker-images/pull/903
9193

hbase/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ ARG DELETE_CACHES="true"
140140
# does not work, so please ignore the according warning (SC2016).
141141
COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/bin/hbck2.env /stackable/bin/
142142
COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/patches /stackable/patches
143+
COPY --chown=${STACKABLE_USER_UID}:0 hbase/stackable/bin/hbase-entrypoint.sh /stackable/bin/
143144

144145
USER ${STACKABLE_USER_UID}
145146
WORKDIR /stackable
@@ -318,6 +319,7 @@ COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-builder /stackable/jmx /stacka
318319

319320
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}/
320321
COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-operator-tools-builder /stackable/bin/hbck2 /stackable/bin/hbck2
322+
COPY --chown=${STACKABLE_USER_UID}:0 --from=hbase-operator-tools-builder /stackable/bin/hbase-entrypoint.sh /stackable/hbase-${PRODUCT}/bin/hbase-entrypoint.sh
321323

322324
COPY --chown=${STACKABLE_USER_UID}:0 --from=phoenix-builder /stackable/phoenix /stackable/phoenix/
323325

@@ -367,4 +369,4 @@ ENV PATH="${PATH}:/stackable/bin:/stackable/hbase/bin"
367369
ENV ASYNC_PROFILER_HOME=/stackable/async-profiler
368370

369371
WORKDIR /stackable/hbase
370-
CMD ["./bin/hbase", "master", "start" ]
372+
CMD ["./bin/hbase-entrypoint", "master", "localhost", "16010" ]
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Entrypoint for HBase that ensures services are shutdown gracefuly
4+
#
5+
# Expects the following env vars:
6+
# - RUN_REGION_MOVER: if set to true, the region mover will be run before region server shutdown
7+
# - REGION_MOVER_OPTS: additional options for the region mover
8+
#
9+
set -x
10+
set -euo pipefail
11+
12+
# master, regionserver, rest
13+
HBASE_ROLE_NAME="$1"
14+
# k8s service name for this role+group combo
15+
# <svc-name>.<namespace>.svc.cluster.local
16+
HBASE_ROLE_SERVICE_NAME="$2"
17+
# 16010 for master, 16020 for regionservers etc.
18+
HBASE_ROLE_SERVICE_PORT="$3"
19+
20+
HBASE_ROLE_SERVICE_HOST="${HOSTNAME}.${HBASE_ROLE_SERVICE_NAME}"
21+
22+
REGION_MOVER_OPTS="--regionserverhost ${HBASE_ROLE_SERVICE_HOST}:${HBASE_ROLE_SERVICE_PORT} --operation unload ${REGION_MOVER_OPTS}"
23+
24+
if [ -f /stackable/kerberos/krb5.conf ]; then
25+
KERBEROS_REALM=$(grep -oP 'default_realm = \K.*' /stackable/kerberos/krb5.conf)
26+
export KERBEROS_REALM
27+
fi
28+
29+
prepare_signal_handlers() {
30+
unset term_child_pid
31+
unset term_kill_needed
32+
trap handle_term_signal TERM
33+
}
34+
35+
handle_term_signal() {
36+
if [ "${term_child_pid}" ]; then
37+
if [ "regionserver" == "${HBASE_ROLE_NAME}" ] && [ "true" == "${RUN_REGION_MOVER}" ]; then
38+
echo "Start pre-shutdown"
39+
# REGION_MOVER_OPTS is a string that contains multiple arguments and needs to be spliced here
40+
# therefore disable shellcheck for this line
41+
# shellcheck disable=SC2086
42+
/stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover ${REGION_MOVER_OPTS}
43+
echo "Done pre-shutdown"
44+
fi
45+
kill -TERM "${term_child_pid}" 2>/dev/null
46+
else
47+
term_kill_needed='yes'
48+
fi
49+
}
50+
51+
wait_for_termination() {
52+
set +e
53+
term_child_pid=$1
54+
if [[ -v term_kill_needed ]]; then
55+
kill -TERM "${term_child_pid}" 2>/dev/null
56+
fi
57+
wait "${term_child_pid}" 2>/dev/null
58+
trap - TERM
59+
wait "${term_child_pid}" 2>/dev/null
60+
set -e
61+
}
62+
63+
# ##################################################################################################
64+
# main
65+
# ##################################################################################################
66+
mkdir -p /stackable/conf
67+
cp /stackable/tmp/hdfs/hdfs-site.xml /stackable/conf
68+
cp /stackable/tmp/hdfs/core-site.xml /stackable/conf
69+
cp /stackable/tmp/hbase/* /stackable/conf
70+
cp /stackable/tmp/log_config/log4j* /stackable/conf
71+
72+
rm -f /stackable/log/_vector/shutdown
73+
prepare_signal_handlers
74+
/stackable/hbase/bin/hbase "${HBASE_ROLE_NAME}" start &
75+
wait_for_termination $!
76+
mkdir -p /stackable/log/_vector && touch /stackable/log/_vector/shutdown

0 commit comments

Comments
 (0)