This repository was archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.sh
More file actions
119 lines (101 loc) · 4.81 KB
/
run.sh
File metadata and controls
119 lines (101 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
echo "Starting Elasticsearch $ES_VERSION"
# Handle discovery service setting. When unset, take out the
# ping.unicast.hosts setting. Usually unset when running
# standalone in Docker directly but needed by Kubernetes.
if [ -z "$ES_DISCOVERY_SERVICE" ]; then
cat "$HOME/config/elasticsearch.yml" | grep -v '^.*ping.unicast.hosts:.*$' > "/tmp/elasticsearch.yml"
mv "/tmp/elasticsearch.yml" "$HOME/config/elasticsearch.yml"
fi
# Rewrite ES_NODE_NAME to HOSTNAME if the former is unset, which
# is usually the case when running standalone in Docker directly.
# In Kubernetes, one usually sets ES_NODE_NAME to metadata.name.
if [ -z "$ES_NODE_NAME" ]; then
ES_NODE_NAME="$HOSTNAME"
cat "$HOME/config/elasticsearch.yml" | sed 's|\${ES_NODE_NAME}|\${HOSTNAME}|g' > "/tmp/elasticsearch.yml"
mv "/tmp/elasticsearch.yml" "$HOME/config/elasticsearch.yml"
fi
# If version is 6.5.0 or higher, we allow setting of
# node.store.allow_mmapfs and we adjust the log pattern format.
ES_VERSION_CONCAT=$(echo $ES_VERSION | sed -e 's|[a-z]||g' -e 's|[A-Z]||g' -e 's|\.||g' -e 's|_||g' -e 's|\-||g' | cut -c 1-3)
if (( $ES_VERSION_CONCAT < 650 )); then
# Not 6.5+, take out 'store:' line.
cat "$HOME/config/elasticsearch.yml" | grep -v '^.*store:.*$' > "/tmp/elasticsearch.yml"
mv "/tmp/elasticsearch.yml" "$HOME/config/elasticsearch.yml"
# Not 6.5+, take out 'allow_mmapfs:' line.
cat "$HOME/config/elasticsearch.yml" | grep -v '^.*allow_mmapfs:.*$' > "/tmp/elasticsearch.yml"
mv "/tmp/elasticsearch.yml" "$HOME/config/elasticsearch.yml"
# Not 6.5+, take out '[%node_name]' element.
cat "$HOME/config/log4j2.properties" | sed 's|\[%node_name\]%marker |%marker|g' > "/tmp/log4j2.properties"
mv /tmp/log4j2.properties "$HOME/config/log4j2.properties"
fi
if (( $ES_VERSION_CONCAT >= 670 )); then
# allow_mmapfs was renamed to allow_mmap, rename.
cat "$HOME/config/elasticsearch.yml" | sed 's|allow_mmapfs|allow_mmap|g' > "/tmp/elasticsearch.yml"
mv "/tmp/elasticsearch.yml" "$HOME/config/elasticsearch.yml"
fi
# Allow for memlock if enabled.
if [ "$ES_MEMORY_LOCK" == "true" ]; then
ulimit -l unlimited
fi
# Create a temporary folder for Elasticsearch ourselves,
# see: https://github.com/elastic/elasticsearch/pull/27659
export ES_TMPDIR="$(mktemp -d -t elasticsearch.XXXXXXXX)"
# Prevent "Text file busy" errors.
sync
if [ ! -z "$ES_PLUGINS_INSTALL" ]; then
OLDIFS="$IFS"
IFS=","
for plugin in $ES_PLUGINS_INSTALL; do
if ! "$HOME/bin/elasticsearch-plugin" list | grep -qs $plugin; then
until "$HOME/bin/elasticsearch-plugin" install --batch $plugin; do
echo "Failed to install $plugin, retrying in 3s"
sleep 3
done
fi
done
IFS="$OLDIFS"
fi
if [ "$ES_SHARD_ALLOCATION_AWARENESS_ENABLED" == "true" ]; then
# This could map to a file like /etc/hostname => /dockerhostname. If it's
# a file, replace the current path specification with the last non-empty,
# not-beginning-with-a-comment-character line of that file, filter out any
# spaces and limit the string length to the first 16 characters.
if [ -f "$ES_SHARD_ALLOCATION_AWARENESS_ATTRIBUTE_VALUE" ]; then
ES_SHARD_ALLOCATION_AWARENESS_ATTRIBUTE_VALUE="$(
cat "$ES_SHARD_ALLOCATION_AWARENESS_ATTRIBUTE_VALUE" |
sed '/^[[:space:]]*$/d' |
sed '/^#/ d' |
tail -n1 |
sed 's/[[:space:]]//g' |
cut -c1-16
)"
fi
# Rewrite the node name by prefixing it with the attribute value.
ES_NODE_NAME="${ES_SHARD_ALLOCATION_AWARENESS_ATTRIBUTE_VALUE}-${ES_NODE_NAME}"
# Add the entry to the configuration file.
echo "node.attr.${ES_SHARD_ALLOCATION_AWARENESS_ATTRIBUTE_KEY}: ${ES_SHARD_ALLOCATION_AWARENESS_ATTRIBUTE_VALUE}" >> "$HOME/config/elasticsearch.yml"
if [ "$ES_NODE_MASTER" == "true" ]; then
echo "cluster.routing.allocation.awareness.attributes: ${ES_SHARD_ALLOCATION_AWARENESS_ATTRIBUTE_KEY}" >> "$HOME/config/elasticsearch.yml"
fi
fi
export ES_NODE_NAME
# Remove x-pack-ml module.
rm -rf "$HOME/modules/x-pack/x-pack-ml"
rm -rf "$HOME/modules/x-pack-ml"
# Run!
if [[ "$(whoami)" == "root" ]]; then
if [ ! -d "/data/data/nodes/0" ]; then
echo "Changing ownership of /data folder"
chown -R elasticsearch:elasticsearch "$HOME/data"
fi
exec su-exec elasticsearch "$HOME/bin/elasticsearch" $ES_EXTRA_ARGS
else
# The container's first process is not running as 'root',
# it does not have the rights to chown. However, we may
# assume that it is being ran as 'elasticsearch', and that
# the volumes already have the right permissions. This is
# the case for Kubernetes, for example, when 'runAsUser: 1000'
# and 'fsGroup:100' are defined in the pod's security context.
"$HOME/bin/elasticsearch" $ES_EXTRA_ARGS
fi