1+ #! /usr/bin/env sh
2+ cp /etc/pki/tls/* /usr/share/elasticsearch/config/
3+ # Parse zone from zone-aware-mapping file based on NODE_NAME
4+ # Zone-aware-mapping file format: YAML format with zone name as key and comma-separated node names as value
5+ # Empty node list is allowed for a zone
6+ # Example:
7+ # zone1: node1,node2
8+ # zone2: node3,node4,node5
9+ # zone3:
10+ ZONE_AWARE_MAPPING_FILE=" /mnt/zone-aware-mapping/mapping"
11+ if [ " ${ZONE_AWARE_ENABLED} " = " true" ]; then
12+ if [ ! -f " ${ZONE_AWARE_MAPPING_FILE} " ]; then
13+ echo " Error: ZONE_AWARE_ENABLED is true but zone-aware-mapping file not found at ${ZONE_AWARE_MAPPING_FILE} "
14+ exit 1
15+ fi
16+ if [ -z " ${NODE_NAME} " ]; then
17+ echo " Error: ZONE_AWARE_ENABLED is true but NODE_NAME is not set"
18+ exit 1
19+ fi
20+ CURRENT_ZONE=" "
21+ ZONES=()
22+ # Parse YAML format: each line is "zone_name: node1,node2,..."
23+ while IFS= read -r LINE || [ -n " ${LINE} " ]; do
24+ # Skip empty lines and comments
25+ LINE=" ${LINE%%#* } " # Remove comments
26+ LINE=$( echo " ${LINE} " | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' ) # Trim whitespace
27+ if [ -z " ${LINE} " ]; then
28+ continue
29+ fi
30+ # Split by first colon to get zone name and node list
31+ ZONE_NAME=" ${LINE%%:* } "
32+ NODE_LIST=" ${LINE#*: } "
33+ # Trim whitespace
34+ ZONE_NAME=$( echo " ${ZONE_NAME} " | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
35+ NODE_LIST=$( echo " ${NODE_LIST} " | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
36+ # Skip if zone name is empty (node list can be empty)
37+ if [ -z " ${ZONE_NAME} " ]; then
38+ continue
39+ fi
40+ # Add zone to ZONES array (even if node list is empty)
41+ ZONES+=(" ${ZONE_NAME} " )
42+ # Check if current node is in this zone (only if not found yet and node list is not empty)
43+ if [ -z " ${CURRENT_ZONE} " ] && [ -n " ${NODE_LIST} " ]; then
44+ IFS=' ,' read -ra NODES <<< " ${NODE_LIST}"
45+ for NODE in " ${NODES[@]} " ; do
46+ NODE_TRIMMED=$( echo " ${NODE} " | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
47+ if [ -n " ${NODE_TRIMMED} " ] && [ " ${NODE_TRIMMED} " = " ${NODE_NAME} " ]; then
48+ export CURRENT_ZONE=" ${ZONE_NAME} "
49+ break
50+ fi
51+ done
52+ fi
53+ done < " ${ZONE_AWARE_MAPPING_FILE} "
54+ if [ -z " ${CURRENT_ZONE} " ]; then
55+ echo " Error: ZONE_AWARE_ENABLED is true but failed to find zone for node ${NODE_NAME} in zone-aware-mapping file"
56+ exit 1
57+ fi
58+ echo " CURRENT_ZONE: ${CURRENT_ZONE} "
59+ # Check if ZONES is empty
60+ if [ ${# ZONES[@]} -eq 0 ]; then
61+ echo " Error: ZONE_AWARE_ENABLED is true but failed to find zones in zone-aware-mapping file"
62+ exit 1
63+ fi
64+ export ALL_ZONES=$( IFS=,; echo " ${ZONES[*]} " )
65+ echo " ALL_ZONES: ${ALL_ZONES} "
66+ fi
67+
68+ # remove initial master nodes block if cluster has been formed
69+ if [ -f " ${CLUSTER_FORMED_FILE} " ]; then
70+ sed -i ' /# INITIAL_MASTER_NODES_BLOCK_START/,/# INITIAL_MASTER_NODES_BLOCK_END/d' config/elasticsearch.yml
71+ fi
72+ if [ -f /bin/tini ]; then
73+ /bin/tini -- /usr/local/bin/docker-entrypoint.sh
74+ elif [ -f /tini ]; then
75+ /tini -- /usr/local/bin/docker-entrypoint.sh
76+ else
77+ /usr/local/bin/docker-entrypoint.sh
78+ fi
0 commit comments