|
| 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