Skip to content

Commit

Permalink
Merge pull request #3 from punktDe/older-versions-support
Browse files Browse the repository at this point in the history
Improve support for older Solr & Tika versions
  • Loading branch information
medanthelinium authored Oct 24, 2023
2 parents a8e6d31 + 8903181 commit d15f4e5
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 31 deletions.
1 change: 1 addition & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
skip_list:
- 'risky-shell-pipe'
- 'role-name'
- 'name[template]'

warn_list:
- package-latest
Expand Down
78 changes: 51 additions & 27 deletions tasks/solr.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions tasks/tika.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions templates/rc.d/solr
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit d15f4e5

Please sign in to comment.