forked from krizsan/elastalert-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-elastalert.sh
40 lines (34 loc) · 1.37 KB
/
start-elastalert.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
#!/bin/sh
set -e
# Set the timezone.
if [ "$SET_CONTAINER_TIMEZONE" = "true" ]; then
setup-timezone -z ${CONTAINER_TIMEZONE} && \
echo "Container timezone set to: $CONTAINER_TIMEZONE"
else
echo "Container timezone not modified"
fi
# Force immediate synchronisation of the time and start the time-synchronization service.
# In order to be able to use ntpd in the container, it must be run with the SYS_TIME capability.
# In addition you may want to add the SYS_NICE capability, in order for ntpd to be able to modify its priority.
ntpd -s
# Wait until Elasticsearch is online since otherwise Elastalert will fail.
rm -f garbage_file
while ! wget -O garbage_file ${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT} 2>/dev/null
do
echo "Waiting for Elasticsearch..."
rm -f garbage_file
sleep 1
done
rm -f garbage_file
sleep 5
# Check if the Elastalert index exists in Elasticsearch and create it if it does not.
if ! wget -O garbage_file ${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}/elastalert_status 2>/dev/null
then
echo "Creating Elastalert index in Elasticsearch..."
elastalert-create-index --host ${ELASTICSEARCH_HOST} --port ${ELASTICSEARCH_PORT} --config ${ELASTALERT_CONFIG} --index elastalert_status --old-index ""
else
echo "Elastalert index already exists in Elasticsearch."
fi
rm -f garbage_file
echo "Starting Elastalert..."
exec supervisord -c ${ELASTALERT_SUPERVISOR_CONF} -n