/
start.sh
executable file
·39 lines (30 loc) · 1.08 KB
/
start.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
#!/usr/bin/env ash
if [ $ELASTICSEARCH_URL ]; then
if [ -z $DRY_RUN ]; then
# wait for elasticsearch to start up
ELASTIC_PATH=${ELASTICSEARCH_URL:-elasticsearch:9200}
echo "Configure ${ELASTIC_PATH}"
counter=0
while [ ! "$(curl $ELASTIC_PATH 2> /dev/null)" -a $counter -lt 30 ]; do
sleep 1
let counter++
echo "waiting for Elasticsearch to be up ($counter/30)"
done
curl -XPUT "http://$ELASTIC_PATH/_template/metricbeat" -d@/metricbeat/metricbeat.template-es2x.json
fi
fi
if [ -z $DRY_RUN ]; then
if [ -z $SKIP_CHOWN_CONFIG ]; then
# Change owner of config file if necessary
USER=$(whoami)
FILE_USER=$(stat -c '%U' /metricbeat/metricbeat.yml)
echo "Metricbeat.yml file owner is $FILE_USER"
if [ "$FILE_USER" != "root" ] && [ "$FILE_USER" != "$USER" ]; then
echo "Change metricbeat.yml file owner to $USER"
chown $USER /metricbeat/metricbeat.yml
fi
fi
# Change permissions of the config file
chmod go-w /metricbeat/metricbeat.yml
metricbeat -e -v -c /metricbeat/metricbeat.yml $@
fi