-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.sh
executable file
·81 lines (67 loc) · 2.56 KB
/
run.sh
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
#!/bin/sh
echo "Starting ElasticSearch $ES_VERSION"
BASE=/elasticsearch
# allow for memlock if enabled
if [ "$MEMORY_LOCK" == "true" ]; then
ulimit -l unlimited
fi
# Set a random node name if not set.
if [ -z "${NODE_NAME}" ]; then
NODE_NAME=$(uuidgen)
fi
export NODE_NAME=${NODE_NAME}
# Create a temporary folder for Elastic Search ourselves.
# Ref: 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 ! $BASE/bin/elasticsearch-plugin list | grep -qs ${plugin}; then
until $BASE/bin/elasticsearch-plugin install --batch ${plugin}; do
echo "failed to install ${plugin}, retrying in 3s"
sleep 3
done
fi
done
IFS=$OLDIFS
fi
if [ ! -z "${SHARD_ALLOCATION_AWARENESS_ATTR}" ]; then
# this will map to a file like /etc/hostname => /dockerhostname so reading that file will get the
# container hostname
if [ "$NODE_DATA" == "true" ]; then
ES_SHARD_ATTR=`cat ${SHARD_ALLOCATION_AWARENESS_ATTR}`
NODE_NAME="${ES_SHARD_ATTR}-${NODE_NAME}"
echo "node.attr.${SHARD_ALLOCATION_AWARENESS}: ${ES_SHARD_ATTR}" >> $BASE/config/elasticsearch.yml
fi
if [ "$NODE_MASTER" == "true" ]; then
echo "cluster.routing.allocation.awareness.attributes: ${SHARD_ALLOCATION_AWARENESS}" >> $BASE/config/elasticsearch.yml
fi
fi
# remove x-pack-ml module
rm -rf /elasticsearch/modules/x-pack/x-pack-ml
rm -rf /elasticsearch/modules/x-pack-ml
# run
if [[ $(whoami) == "root" ]]; then
#chown -R elasticsearch:elasticsearch $BASE
#chown -R elasticsearch:elasticsearch /data
echo "Changing ownership of $BASE folder"
find . -type f -print0 | xargs -0 chown elasticsearch:elasticsearch $BASE
echo "Changing ownership of /data folder"
find . -type f -print0 | xargs -0 chown elasticsearch:elasticsearch /data
exec su-exec elasticsearch $BASE/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.
$BASE/bin/elasticsearch $ES_EXTRA_ARGS &
fi
# Wait for ES to start then initialize SearchGuard
/wait_until_started.sh
/sgadmin.sh
wait