From cff4fc38b39f4256a2b07ec56558e052a293fa68 Mon Sep 17 00:00:00 2001 From: phil Date: Thu, 11 May 2023 08:46:18 +0200 Subject: [PATCH] Opensearch: Aktualisiere Plugins bei Paket-Updates --- defaults/main.yml | 3 ++ tasks/opensearch.yml | 15 +++++++- templates/72opensearch-updates.j2 | 5 +++ .../{opensearch.monit => opensearch.monit.j2} | 4 ++- templates/update-opensearch-plugins.j2 | 35 +++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 templates/72opensearch-updates.j2 rename templates/{opensearch.monit => opensearch.monit.j2} (69%) create mode 100644 templates/update-opensearch-plugins.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 7505269..83f8768 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -6,6 +6,9 @@ opensearch: http_port: 9200 attachment_max_size: 50 +opensearch_plugin_update_script: update-opensearch-plugins +opensearch_monit_service: opensearch + ruby_path: "{{ zammad_user_home }}/.rbenv" ruby_bin_path: "{{ ruby_path }}/versions/{{ ruby_version }}/bin" ruby_build_repo: https://github.com/rbenv/ruby-build.git diff --git a/tasks/opensearch.yml b/tasks/opensearch.yml index 9f9b2a1..536d022 100644 --- a/tasks/opensearch.yml +++ b/tasks/opensearch.yml @@ -92,7 +92,20 @@ - name: "Opensearch | Richte Monit-Überwachung ein" ansible.builtin.template: - src: opensearch.monit + src: opensearch.monit.j2 dest: /etc/monit/conf-enabled/opensearch mode: "0644" notify: reload monit + +- name: "Opensearch | Kopiere Update-Skript" + ansible.builtin.template: + src: update-opensearch-plugins.j2 + dest: "/usr/local/bin/{{ opensearch_plugin_update_script }}" + mode: "0755" + +- name: "Opensearch | Kopiere DPKG-Hook" + ansible.builtin.template: + src: 72opensearch-updates.j2 + dest: /etc/apt/apt.conf.d/72opensearch-updates + mode: "0644" + \ No newline at end of file diff --git a/templates/72opensearch-updates.j2 b/templates/72opensearch-updates.j2 new file mode 100644 index 0000000..bdf3334 --- /dev/null +++ b/templates/72opensearch-updates.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} +# Neuinstallation der Plugins + +DPkg::Pre-Invoke {"/usr/local/bin//{{ opensearch_plugin_update_script }} purge";}; +DPkg::Post-Invoke {"/usr/local/bin//{{ opensearch_plugin_update_script }} install";}; diff --git a/templates/opensearch.monit b/templates/opensearch.monit.j2 similarity index 69% rename from templates/opensearch.monit rename to templates/opensearch.monit.j2 index ab5d0af..c9eefff 100644 --- a/templates/opensearch.monit +++ b/templates/opensearch.monit.j2 @@ -1,4 +1,6 @@ -check process opensearch with pidfile /run/opensearch/opensearch.pid +# {{ ansible_managed }} + +check process {{ opensearch_monit_service }} with pidfile /run/opensearch/opensearch.pid start program = "/usr/sbin/service opensearch start" stop program = "/usr/sbin/service opensearch stop" if failed host {{ opensearch.network_host }} port {{ opensearch.http_port }} for 3 cycles then restart diff --git a/templates/update-opensearch-plugins.j2 b/templates/update-opensearch-plugins.j2 new file mode 100644 index 0000000..b00a65a --- /dev/null +++ b/templates/update-opensearch-plugins.j2 @@ -0,0 +1,35 @@ +#!/bin/sh +# {{ ansible_managed }} + +set -eu + +OPENSEARCH_BIN_PATH=/usr/share/opensearch/bin +OPENSEARCH_SERVICE=opensearch.service +PLUGINS=( + ingest-attachment +) + +ACTION="${1:-help}" + +case "$ACTION" in + purge) + for plugin in "${PLUGINS[@]}"; do + $OPENSEARCH_BIN_PATH/opensearch-plugin remove $plugin --batch + done + systemctl restart $OPENSEARCH_SERVICE + ;; + install) + for plugin in "${PLUGINS[@]}"; do + $OPENSEARCH_BIN_PATH/opensearch-plugin install $plugin --batch + done + systemctl restart $OPENSEARCH_SERVICE + ;; + help) + echo "Syntax: $(basename "$0") { purge | install | help }" + echo + ;; + *) + "$0" help >&2 + exit 1 + ;; +esac