From 89031814c220e72c0f8c040a263070ad59e80855 Mon Sep 17 00:00:00 2001 From: Wolfgang Medina-Erhardt Date: Mon, 16 Oct 2023 13:34:34 +0200 Subject: [PATCH] Improve support for older Solr & Tika version --- .ansible-lint | 1 + tasks/solr.yaml | 78 +++++++++++++++++++++++++++++---------------- tasks/tika.yaml | 11 ++++--- templates/rc.d/solr | 39 +++++++++++++++++++++++ 4 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 templates/rc.d/solr diff --git a/.ansible-lint b/.ansible-lint index 09987cd..35bb270 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -2,6 +2,7 @@ skip_list: - 'risky-shell-pipe' - 'role-name' + - 'name[template]' warn_list: - package-latest diff --git a/tasks/solr.yaml b/tasks/solr.yaml index 6befc90..d6abc8b 100644 --- a/tasks/solr.yaml +++ b/tasks/solr.yaml @@ -1,26 +1,48 @@ --- -- name: Create program directory for Solr +- name: Create program directory for Solr ansible.builtin.file: path: "{{ item }}" state: directory - owner: root - group: "{{ root_group }}" + owner: solr + group: solr mode: "0755" with_items: - "{{ solr.prefix.bin }}" -- name: Download Solr +- name: Download Solr {{ solr.version }} ansible.builtin.get_url: - url: "https://archive.apache.org/dist/solr/solr/{{ solr.version }}/solr-{{ solr.version }}.tgz" - dest: "{{ item }}" - checksum: "sha512:https://archive.apache.org/dist/solr/solr/{{ solr.version }}/solr-{{ solr.version }}.tgz.sha512" - owner: root - group: "{{ root_group }}" + url: "https://archive.apache.org/dist/{{ solr_path_segment }}/solr/{{ solr.version }}/solr-{{ solr.version }}.tgz" + dest: "{{ solr.prefix.bin }}/solr-{{ solr.version }}.tar.gz" + checksum: "{{ checksum_version }}:https://archive.apache.org/dist/{{ solr_path_segment }}/solr/{{ solr.version }}/solr-{{ solr.version }}.tgz.{{ checksum_version }}" + owner: solr + group: solr mode: "0644" - with_items: - - "{{ solr.prefix.bin }}/solr-{{ solr.version }}.tar.gz" + vars: + solr_path_segment: "{{ 'solr' if solr.version[0] is ansible.builtin.version('9', '>=') else 'lucene' }}" + checksum_version: "{{ 'sha512' if solr.version[0] is ansible.builtin.version('9', '>=') else 'sha1' }}" register: solr_get_url_result +- name: Ignore unrecognized JVM options (for versions older than 9) + notify: Restart Solr + when: solr.version[0] is ansible.builtin.version('9', '<') + ansible.builtin.template: + dest: "/etc/rc.d/solr" + src: "rc.d/solr" + owner: root + mode: "0755" + +- name: Don't ignore unrecognized JVM options (for versions newer than 9) + notify: Restart Solr + when: solr.version[0] is ansible.builtin.version('9', '>=') + ansible.builtin.file: + path: "/etc/rc.d/solr" + state: absent + +- name: Check if {{ solr.prefix.bin }}/bin exists + register: solr_bin_exists + ansible.builtin.stat: + path: "{{ solr.prefix.bin }}/bin" + - name: Handle Solr update when: solr_get_url_result.changed block: @@ -29,13 +51,10 @@ name: solr state: stopped - - name: Disable Solr service - ansible.builtin.lineinfile: - path: "{{ item }}" - regexp: "^solr_enable=" - line: 'solr_enable="NO"' - with_items: - - /etc/rc.conf + - name: Kill all solr processes + changed_when: yes + ansible.builtin.command: + cmd: "killall -u solr" - name: Remove old Solr version changed_when: yes @@ -45,15 +64,20 @@ with_items: - "{{ solr.prefix.bin }}" - - name: Unarchive Solr - ansible.builtin.unarchive: - src: "{{ solr.prefix.bin }}/solr-{{ solr.version }}.tar.gz" - dest: "{{ item }}" - extra_opts: - - --strip-components=1 - remote_src: yes - with_items: - - "{{ solr.prefix.bin }}" +- name: Unarchive Solr + when: solr_get_url_result.changed or not solr_bin_exists.stat.exists + notify: Restart Solr + ignore_errors: "{{ ansible_check_mode }}" + ansible.builtin.unarchive: + src: "{{ solr.prefix.bin }}/solr-{{ solr.version }}.tar.gz" + owner: solr + group: solr + dest: "{{ item }}" + extra_opts: + - --strip-components=1 + remote_src: yes + with_items: + - "{{ solr.prefix.bin }}" - name: Sync Solr config diff --git a/tasks/tika.yaml b/tasks/tika.yaml index b1a5e3f..761183b 100644 --- a/tasks/tika.yaml +++ b/tasks/tika.yaml @@ -9,14 +9,17 @@ with_items: - "{{ solr.tika.prefix.bin }}" -- name: Download Tika +- name: Download Tika {{ solr.tika.version }} + register: tika_get_url_result ansible.builtin.get_url: - url: "https://archive.apache.org/dist/tika/{{ solr.tika.version }}/tika-server-standard-{{ solr.tika.version }}.jar" - dest: "{{ solr.tika.prefix.bin }}/tika-server-{{ solr.tika.version }}.jar" - checksum: "sha512:https://archive.apache.org/dist/tika/{{ solr.tika.version }}/tika-server-standard-{{ solr.tika.version }}.jar.sha512" + url: "https://archive.apache.org/dist/tika/{{ solr.tika.version }}/tika-server-{{ tika_standard }}{{ solr.tika.version }}.jar" + dest: "{{ solr.tika.prefix.bin }}/tika-server.jar" + checksum: "sha512:https://archive.apache.org/dist/tika/{{ solr.tika.version }}/tika-server-{{ tika_standard }}{{ solr.tika.version }}.jar.sha512" owner: root group: "{{ root_group }}" mode: "0755" + vars: + tika_standard: "{{ 'standard-' if solr.tika.version is version('2', '>=') else '' }}" notify: Restart Tika - name: Install Tika service diff --git a/templates/rc.d/solr b/templates/rc.d/solr new file mode 100644 index 0000000..d717571 --- /dev/null +++ b/templates/rc.d/solr @@ -0,0 +1,39 @@ +#!/bin/sh +# PROVIDE: solr +# REQUIRE: LOGIN +# KEYWORD: shutdown + +. /etc/rc.subr + +name=solr +rcvar=solr_enable +load_rc_config $name + +: ${solr_enable:=NO} +: ${solr_instance:=/var/db/solr} + +solr_start () +{ + su -m solr -c "${command} start -a '-XX:+IgnoreUnrecognizedVMOptions'" +} + +solr_stop () +{ + su -m solr -c "${command} stop" +} + +solr_status () +{ + su -m solr -c "${command} status" +} + +# add /usr/local/bin to path +export PATH=$PATH:/usr/local/bin + +required_files="${solr_instance}/solr.xml /usr/local/etc/solr.in.sh /usr/local/solr" +command=/usr/local/solr/bin/solr +start_cmd=solr_start +stop_cmd=solr_stop +status_cmd=solr_status + +run_rc_command "$1"