From 0a02a820f1561d4fcf6c15da52f77aea2d24dbb6 Mon Sep 17 00:00:00 2001 From: Carles Figuerola Date: Thu, 18 May 2017 11:55:15 -0700 Subject: [PATCH 1/6] Add a variable to provide a list of masters and update readme --- docker-entrypoint.sh | 18 +++++++++++++++++- readme.md | 6 +++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 83c972a..674dca4 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -7,6 +7,22 @@ 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_URL=http://$(echo $response | awk '{printf $NF}'):9200 + echo "Master found: $ELASTICSEARCH_URL" + 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" @@ -15,4 +31,4 @@ 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 "$@" \ No newline at end of file +exec "$@" diff --git a/readme.md b/readme.md index 4a49efb..ee5123a 100644 --- a/readme.md +++ b/readme.md @@ -4,10 +4,10 @@ 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:9200" 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 From 52134b6a62b492e9c213e3496a6d7d2df456066e Mon Sep 17 00:00:00 2001 From: Carles Figuerola Date: Thu, 18 May 2017 14:25:36 -0500 Subject: [PATCH 2/6] Had the wrongly named variable --- docker-entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 674dca4..bbb04e9 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -16,8 +16,8 @@ then response=$(wget -qO- http://${master}:9200/_cat/master) if [ "$?" -eq 0 ] then - ELASTICSEARCH_URL=http://$(echo $response | awk '{printf $NF}'):9200 - echo "Master found: $ELASTICSEARCH_URL" + ELASTICSEARCH_HOST=http://$(echo $response | awk '{printf $NF}'):9200 + echo "Master found: $ELASTICSEARCH_HOST" break fi done From 270fe4c110eb5ecd1d4395961d1862aadd91fd56 Mon Sep 17 00:00:00 2001 From: Carles Figuerola Date: Thu, 18 May 2017 14:37:36 -0500 Subject: [PATCH 3/6] curator doesn't expect http or port number --- docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index bbb04e9..2582465 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -16,7 +16,7 @@ then response=$(wget -qO- http://${master}:9200/_cat/master) if [ "$?" -eq 0 ] then - ELASTICSEARCH_HOST=http://$(echo $response | awk '{printf $NF}'):9200 + ELASTICSEARCH_HOST=$(echo $response | awk '{printf $NF}') echo "Master found: $ELASTICSEARCH_HOST" break fi From eeb757c07485e84c3e378424c5a6b3c862a1ef2a Mon Sep 17 00:00:00 2001 From: Carles Figuerola Date: Thu, 18 May 2017 14:43:38 -0500 Subject: [PATCH 4/6] Up version 3.5.1 to close #1 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d8e2c93..e1ab662 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ 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 / From 07d6038f7d89c4519b00932cef20dc0241bbc807 Mon Sep 17 00:00:00 2001 From: Carles Figuerola Date: Thu, 18 May 2017 14:46:45 -0500 Subject: [PATCH 5/6] Forgot to take out the port number from the readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index ee5123a..9dce255 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ 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" -e ELASTICSEARCH_HOST="localhost:9200" visity/elasticsearch-curator + docker run -d -e INTERVAL_IN_HOURS=24 -e OLDER_THAN_IN_DAYS="10" -e ELASTICSEARCH_HOST="localhost" visity/elasticsearch-curator * **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. From ad6e80718e71d1671305aae8f4cd534d4aef1eb8 Mon Sep 17 00:00:00 2001 From: Carles Figuerola Date: Thu, 14 Sep 2017 10:10:13 -0500 Subject: [PATCH 6/6] Add configurable port --- Dockerfile | 1 + docker-entrypoint.sh | 2 +- readme.md | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e1ab662..57783ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ 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"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2582465..9f5ffc2 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -25,7 +25,7 @@ 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, diff --git a/readme.md b/readme.md index 9dce255..92bb821 100644 --- a/readme.md +++ b/readme.md @@ -10,4 +10,5 @@ It can be run as follows: * **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