|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Entrypoint for HBase that ensures services are shutdown gracefuly |
| 4 | +# |
| 5 | +set -x |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +HBASE_ROLE_NAME="$1" |
| 9 | +HBASE_ROLE_SERVICE_NAME="$2" |
| 10 | +HBASE_ROLE_SERVICE_PORT="$3" |
| 11 | + |
| 12 | +# TODO: remove hard coded svc.cluster.local |
| 13 | +HBASE_ROLE_SERVICE_HOST="${HOSTNAME}.${HBASE_ROLE_SERVICE_NAME}.${NAMESPACE}.svc.cluster.local" |
| 14 | + |
| 15 | +REGION_MOVER_OPTS="--regionserverhost ${HBASE_ROLE_SERVICE_HOST}:${HBASE_ROLE_SERVICE_PORT} --operation unload ${REGION_MOVER_OPTS}" |
| 16 | + |
| 17 | +prepare_signal_handlers() { |
| 18 | + unset term_child_pid |
| 19 | + unset term_kill_needed |
| 20 | + trap handle_term_signal TERM |
| 21 | +} |
| 22 | + |
| 23 | +handle_term_signal() { |
| 24 | + if [ "${term_child_pid}" ]; then |
| 25 | + if [ "regionserver" == "${HBASE_ROLE_NAME}" ]; then |
| 26 | + echo "Running pre-shutdown command: /stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover ${REGION_MOVER_OPTS}" |
| 27 | + /stackable/hbase/bin/hbase org.apache.hadoop.hbase.util.RegionMover "${REGION_MOVER_OPTS}" |
| 28 | + echo "Done pre-shutdown command" |
| 29 | + fi |
| 30 | + kill -TERM "${term_child_pid}" 2>/dev/null |
| 31 | + else |
| 32 | + term_kill_needed='yes' |
| 33 | + fi |
| 34 | +} |
| 35 | + |
| 36 | +wait_for_termination() { |
| 37 | + set +e |
| 38 | + term_child_pid=$1 |
| 39 | + if [[ -v term_kill_needed ]]; then |
| 40 | + kill -TERM "${term_child_pid}" 2>/dev/null |
| 41 | + fi |
| 42 | + wait "${term_child_pid}" 2>/dev/null |
| 43 | + trap - TERM |
| 44 | + wait "${term_child_pid}" 2>/dev/null |
| 45 | + set -e |
| 46 | +} |
| 47 | + |
| 48 | +# ################################################################################################## |
| 49 | +# main |
| 50 | +# ################################################################################################## |
| 51 | +mkdir -p /stackable/conf |
| 52 | +cp /stackable/tmp/hdfs/hdfs-site.xml /stackable/conf |
| 53 | +cp /stackable/tmp/hdfs/core-site.xml /stackable/conf |
| 54 | +cp /stackable/tmp/hbase/* /stackable/conf |
| 55 | +cp /stackable/tmp/log_config/log4j.properties /stackable/conf |
| 56 | + |
| 57 | +rm -f /stackable/log/_vector/shutdown |
| 58 | +prepare_signal_handlers |
| 59 | +/stackable/hbase/bin/hbase "${HBASE_ROLE_NAME}" start & |
| 60 | +wait_for_termination $! |
| 61 | +mkdir -p /stackable/log/_vector && touch /stackable/log/_vector/shutdown |
0 commit comments