Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a variable to provide a list of masters and update readme #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ RUN arch="$(dpkg --print-architecture)" \
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r curator && useradd -r -g curator curator

RUN pip install elasticsearch-curator==3.4.0
RUN pip install elasticsearch-curator==3.5.1

COPY docker-entrypoint.sh /

ENV INTERVAL_IN_HOURS=24
ENV OLDER_THAN_IN_DAYS="20"
ENV ELASTICSEARCH_HOST=elasticsearch
ENV ELASTICSEARCH_PORT=9200

ENTRYPOINT ["/docker-entrypoint.sh"]

Expand Down
20 changes: 18 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,28 @@ if [ "${1:0:1}" = '-' ]; then
set -- curator "$@"
fi

## Find out who is the master
if [[ ${ELASTICSEARCH_MASTERS} ]]
then
echo "Finding elasticsearch master from: $ELASTICSEARCH_MASTERS"
for master in ${ELASTICSEARCH_MASTERS//,/ }
do
response=$(wget -qO- http://${master}:9200/_cat/master)
if [ "$?" -eq 0 ]
then
ELASTICSEARCH_HOST=$(echo $response | awk '{printf $NF}')
echo "Master found: $ELASTICSEARCH_HOST"
break
fi
done
fi

# Step down via gosu
if [ "$1" = 'curator' ]; then
exec gosu curator bash -c "while true; do curator --host $ELASTICSEARCH_HOST delete indices --older-than $OLDER_THAN_IN_DAYS --time-unit=days --timestring '%Y.%m.%d'; set -e; sleep $(( 60*60*INTERVAL_IN_HOURS )); set +e; done"
exec gosu curator bash -c "while true; do curator --host $ELASTICSEARCH_HOST --port $ELASTICSEARCH_PORT delete indices --older-than $OLDER_THAN_IN_DAYS --time-unit=days --timestring '%Y.%m.%d'; set -e; sleep $(( 60*60*INTERVAL_IN_HOURS )); set +e; done"
fi

# As argument is not related to curator,
# then assume that user wants to run his own process,
# for example a `bash` shell to explore this image
exec "$@"
exec "$@"
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ This only job executed by the docker built from this repository is to clean the

It can be run as follows:

docker run -d -e INTERVAL_IN_HOURS=24 -e OLDER_THAN_IN_DAYS="10" --link es1:elasticsearch visity/elasticsearch-curator
docker run -d -e INTERVAL_IN_HOURS=24 -e OLDER_THAN_IN_DAYS="10" -e ELASTICSEARCH_HOST="localhost" visity/elasticsearch-curator

where **es1** is the name of the elasticsearch container and

* **INTERVAL\_IN\_HOURS**: The amount of time between two curator runs
* **OLDER\_THAN\_IN\_DAYS**: Indicates all logs with a date exceeding this age can be deleted.
* **ELASTICSEARCH\_HOST**: Points to the elasticsearch master url
* **ELASTICSEARCH\_MASTERS**: Optionally, other than ELASTICSEARCH\_HOST, a list of hosts can be provided here and the master will be chosen amongst them
* **ELASTICSEARCH\_PORT**: Port to access elasticsearch. It defaults to 9200