From 39ba855c311da77877287256b86fbb2afb9ea235 Mon Sep 17 00:00:00 2001 From: Peter Razumovsky Date: Fri, 10 Mar 2017 13:21:51 +0000 Subject: [PATCH] Move elasticsearch service to actual repo Change-Id: I977d6a40a5b700278ff4b69861341cf3b434e7da --- docker/cron/Dockerfile.j2 | 8 +++++ docker/elasticsearch/Dockerfile.j2 | 20 +++++++++++ service/elasticsearch.yaml | 36 +++++++++++++++++++ .../curator-action-delete-indice.yaml.j2 | 29 +++++++++++++++ service/files/curator-cronjob | 1 + service/files/curator.yaml.j2 | 13 +++++++ service/files/defaults.yaml | 10 ++++++ service/files/elasticsearch.yml.j2 | 11 ++++++ 8 files changed, 128 insertions(+) create mode 100644 docker/cron/Dockerfile.j2 create mode 100644 docker/elasticsearch/Dockerfile.j2 create mode 100644 service/elasticsearch.yaml create mode 100644 service/files/curator-action-delete-indice.yaml.j2 create mode 100644 service/files/curator-cronjob create mode 100644 service/files/curator.yaml.j2 create mode 100644 service/files/defaults.yaml create mode 100644 service/files/elasticsearch.yml.j2 diff --git a/docker/cron/Dockerfile.j2 b/docker/cron/Dockerfile.j2 new file mode 100644 index 0000000..601a2d6 --- /dev/null +++ b/docker/cron/Dockerfile.j2 @@ -0,0 +1,8 @@ +FROM {{ image_spec("base-tools") }} +MAINTAINER {{ maintainer }} + +RUN apt-get -y install --no-install-recommends \ + cron \ + logrotate \ + && apt-get clean \ + && pip install --no-cache-dir elasticsearch-curator=={{ elasticsearch_curator_version }} diff --git a/docker/elasticsearch/Dockerfile.j2 b/docker/elasticsearch/Dockerfile.j2 new file mode 100644 index 0000000..d886791 --- /dev/null +++ b/docker/elasticsearch/Dockerfile.j2 @@ -0,0 +1,20 @@ +FROM {{ image_spec("base-tools") }} +MAINTAINER {{ maintainer }} + +ENV JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk-amd64/ + +RUN apt-get -y install --no-install-recommends -t jessie-backports openjdk-8-jre \ + && curl https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/{{ elasticsearch_version }}/elasticsearch-{{ elasticsearch_version }}.deb -o /tmp/elasticsearch.deb \ + && dpkg -i /tmp/elasticsearch.deb \ + && rm -f /tmp/elasticsearch.deb \ + && apt-get clean + +RUN usermod -a -G microservices elasticsearch \ + && chown -R elasticsearch: /usr/share/elasticsearch + +# by default elasticsearch shell is /bin/false, we need +# /bin/bash to run elasticsearch as non-root +# https://discuss.elastic.co/t/running-as-non-root-user-service-wrapper-has-changed/7863 +RUN usermod -s /bin/bash elasticsearch -d /usr/share/elasticsearch + +USER elasticsearch diff --git a/service/elasticsearch.yaml b/service/elasticsearch.yaml new file mode 100644 index 0000000..1969012 --- /dev/null +++ b/service/elasticsearch.yaml @@ -0,0 +1,36 @@ +dsl_version: 0.7.0 +service: + name: elasticsearch + ports: + - {{ elasticsearch.port }} + - {{ elasticsearch.cluster_port }} + containers: + - name: elasticsearch + image: elasticsearch + daemon: + command: /usr/share/elasticsearch/bin/elasticsearch + files: + - elasticsearch.yml + - name: cron + image: cron + daemon: + command: cron -f + files: + - es-curator-config + - es-curator-action-delete-indice + - es-curator-cronjob + +files: + elasticsearch.yml: + path: /usr/share/elasticsearch/config/elasticsearch.yml + content: elasticsearch.yml.j2 + es-curator-config: + path: /etc/curator/curator.yaml + content: curator.yaml.j2 + es-curator-action-delete-indice: + path: /etc/curator/action-delete-indice.yaml + content: curator-action-delete-indice.yaml.j2 + es-curator-cronjob: + path: /etc/cron.d/curator + content: curator-cronjob + perm: "0644" diff --git a/service/files/curator-action-delete-indice.yaml.j2 b/service/files/curator-action-delete-indice.yaml.j2 new file mode 100644 index 0000000..2421050 --- /dev/null +++ b/service/files/curator-action-delete-indice.yaml.j2 @@ -0,0 +1,29 @@ +--- +# Remember, leave a key empty if there is no value. None will be a string, +# not a Python "NoneType" +actions: + 1: + action: delete_indices + description: >- + Delete indices older than {{ elasticsearch.retention_period }} days + (based on index name), for 'log-' prefixed indices. Ignore the error + if the filter does not result in an actionable list of indices + (ignore_empty_list) and exit cleanly. + options: + ignore_empty_list: True + timeout_override: + continue_if_exception: False + disable_action: False + filters: + - filtertype: pattern + kind: prefix + value: log- + exclude: + - filtertype: age + source: name + direction: older + timestring: '%Y.%m.%d' + unit: days + unit_count: {{ elasticsearch.retention_period }} + exclude: + diff --git a/service/files/curator-cronjob b/service/files/curator-cronjob new file mode 100644 index 0000000..9bfc7b7 --- /dev/null +++ b/service/files/curator-cronjob @@ -0,0 +1 @@ +@daily root curator --config /etc/curator/curator.yaml /etc/curator/action-delete-indice.yaml diff --git a/service/files/curator.yaml.j2 b/service/files/curator.yaml.j2 new file mode 100644 index 0000000..fe19e51 --- /dev/null +++ b/service/files/curator.yaml.j2 @@ -0,0 +1,13 @@ +--- +# Remember, leave a key empty if there is no value. None will be a string, +# not a Python "NoneType" +client: + hosts: + - localhost + port: {{ elasticsearch.port.cont }} + url_prefix: + use_ssl: False + certificate: + ssl_no_validate: False + timeout: 30 + master_only: True diff --git a/service/files/defaults.yaml b/service/files/defaults.yaml new file mode 100644 index 0000000..176491e --- /dev/null +++ b/service/files/defaults.yaml @@ -0,0 +1,10 @@ +configs: + elasticsearch: + port: + cont: 9200 + cluster_port: + cont: 9300 + retention_period: 30 +versions: + elasticsearch_version: "2.4.0" + elasticsearch_curator_version: "4.1.0" diff --git a/service/files/elasticsearch.yml.j2 b/service/files/elasticsearch.yml.j2 new file mode 100644 index 0000000..6179552 --- /dev/null +++ b/service/files/elasticsearch.yml.j2 @@ -0,0 +1,11 @@ +node.name: "{{ network_topology["private"]["address"] }}" +network.host: [ "127.0.0.1", "{{ network_topology["private"]["address"] }}" ] +cluster.name: "ELASTIC" +node.master: true +node.data: true +gateway.expected_nodes: 1 + +path.conf: "/etc/elasticsearch" +path.data: "/var/lib/elasticsearch/data" +path.logs: "/var/log/elasticsearch" +path.scripts: "/etc/elasticsearch/scripts"