|
6 | 6 | # given externally they are used with precedence. |
7 | 7 |
|
8 | 8 | # Get the number of the Elasticsearch node based on the node.name (e.g. elasticsearch2) |
9 | | -nodeBasename=`echo node.name | awk 'match(ENVIRON[$0], /([a-zA-Z]*)([0-9]{1,})/, v) { print v[1] }'` |
10 | | -nodeNumber=`echo node.name | awk 'match(ENVIRON[$0], /([a-zA-Z]*)([0-9]{1,})/, v) { print v[2] }'` |
| 9 | +echo "Setup Elasticsearch cluster based on ELASTICSEARCH_HOSTS: ${ELASTICSEARCH_HOSTS}" |
| 10 | +# Translate the dotted environment variable into Non-Dotted to avoid issues with Bash commands |
| 11 | +nodeName=`echo | awk '{ print ENVIRON["node.name"] }'` |
| 12 | + |
| 13 | +nodeBasename=`echo $nodeName | sed -r 's/([a-zA-Z]*)([0-9]{1,})/\1/'` |
| 14 | +nodeNumber=`echo $nodeName | sed -r 's/([a-zA-Z]*)([0-9]{1,})/\2/'` |
11 | 15 |
|
12 | 16 | count=1 |
13 | 17 | params="" |
|
23 | 27 | fi |
24 | 28 | # Use all declared hosts as seed hosts if |
25 | 29 | # Seeds hosts are not given externally and the standard transport ports are used |
26 | | - discoverySeedHosts=`echo discovery.seed_hosts | awk '{print ENVIRON[$0]}'` |
27 | | - discoveryTransportPort=`echo transport.port | awk '{print ENVIRON[$0]}'` |
| 30 | + discoverySeedHosts=`echo | awk '{ print ENVIRON["discovery.seed_hosts"] }'` |
| 31 | + discoveryTransportPort=`echo | awk '{ print ENVIRON["transport.port"] }'` |
28 | 32 | if [ -z "${discoverySeedHosts}" -a -z "${discoveryTransportPort}" ] |
29 | 33 | then |
30 | | - # Get the hostname and transport from the URL |
31 | | - discoverPublishHostname=`echo $host | awk 'match($0, /https?:\/\/(.*)\:(\d*)/, v) { print v[1] }'` |
32 | | - discoveryTransportPort=`echo $host | awk 'match($0,/https?:\/\/(.*)\:[0-9]{2}([0-9]{2})/, v) { print 93v[2] }'` |
| 34 | + # Get the hostname and defined transportPort based on the URL (e.g. https://elasticsearch2:9201) 9201 --> 9301 |
| 35 | + discoverPublishHostname=`echo $host | sed -r 's/https?:\/\/(.*)\:[0-9]{4}/\1/'` |
| 36 | + discoveryTransportPort=`echo $host | sed -r 's/https?:\/\/(.*)\:[0-9]{2}([0-9]{2})/93\2/'` |
33 | 37 | if [ "${seedHosts}" == "" ]; then |
34 | 38 | seedHosts="-E discovery.seed_hosts=${discoverPublishHostname}:${discoveryTransportPort}" |
35 | 39 | else |
|
39 | 43 |
|
40 | 44 | if [ "${count}" == "${nodeNumber}" ]; then |
41 | 45 | echo "Setting up Elasticsearch node: ${nodeNumber}" |
42 | | - publishHost=`echo network.publish_host | awk '{print ENVIRON[$0]}'` |
| 46 | + publishHost=`echo | awk '{ print ENVIRON["network.publish_host"] }'` |
43 | 47 | if [ -z "${publishHost}" ]; then |
44 | | - publishHost=`echo $host | awk 'match($0, /https?:\/\/(.*)\:(\d*)/, v) { print v[1] }'` |
| 48 | + publishHost=`echo $host | sed -r 's/https?:\/\/(.*)\:[0-9]{4}/\1/'` |
45 | 49 | params="$params -E network.publish_host=${publishHost}" |
46 | 50 | echo "Set network.publish_host=${publishHost} based on given host: ${host}" |
47 | 51 | else |
|
51 | 55 | httpPort=`echo http.port | awk '{print ENVIRON[$0]}'` |
52 | 56 | if [ -z "${httpPort}" ] |
53 | 57 | then |
54 | | - httpPort=`echo $host | awk 'match($0,/https?:\/\/(.*)\:([0-9]*)/, v) { print v[2] }'` |
| 58 | + httpPort=`echo $host | sed -r 's/https?:\/\/(.*)\:([0-9]*)/\2/'` |
55 | 59 | params="$params -E http.port=${httpPort}" |
56 | 60 | echo "Set http.port=${httpPort} based on given host: ${host}" |
57 | 61 | else |
58 | 62 | echo "http.port=${httpPort} taken from envionment variable" |
59 | 63 | fi |
60 | 64 |
|
61 | | - transportPort=`echo transport.port | awk '{print ENVIRON[$0]}'` |
| 65 | + transportPort=`echo | awk '{ print ENVIRON["transport.port"] }'` |
62 | 66 | if [ -z "${transportPort}" ] |
63 | 67 | then |
64 | | - transportPort=`echo $host | awk 'match($0,/https?:\/\/(.*)\:[0-9]{2}([0-9]{2})/, v) { print 93v[2] }'` |
| 68 | + transportPort=`echo $host | sed -r 's/https?:\/\/(.*)\:[0-9]{2}([0-9]{2})/93\2/'` |
65 | 69 | params="$params -E transport.port=${transportPort}" |
66 | 70 | echo "Set transport.port=${transportPort} based on given host: ${host}" |
67 | 71 | else |
|
0 commit comments