Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: solr listen on custom network interface #143

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ The path where local Solr data (search collections and configuration) will be st

solr_port: "8983"

The port on which Solr will run.
The port on which Solr will run.

solr_jetty_host: "127.0.0.1"

The network interface on which Solr will listen. You can define a value different than 127.0.0.1 just for solr version 9.3.0 and higher.

solr_xms: "256M"
solr_xmx: "512M"
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
solr_home: "/var/{{ solr_service_name }}"
solr_connect_host: localhost
solr_port: "8983"
solr_jetty_host: "127.0.0.1"

solr_xms: "256M"
solr_xmx: "512M"
Expand All @@ -29,7 +30,7 @@
solr_cores:
- collection1

solr_default_core_path: "{% if solr_version.split('.')[0] < '9' %}{{ solr_install_path }}/example/files/conf/{% else %}{{ solr_install_path }}/server/solr/configsets/_default/conf/{% endif %}"

Check warning on line 33 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint

33:121 [line-length] line too long (192 > 120 characters)

solr_config_file: /etc/default/{{ solr_service_name }}.in.sh

Expand Down
5 changes: 5 additions & 0 deletions tasks/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Check for incompatible solr_jetty_host
fail:
msg: 'You can set solr_jetty_host other than 127.0.0.1 only when the Solr version is 9.3.0 or higher'
when: solr_jetty_host != '127.0.0.1' and solr_version is version('9.3.0' ,'<')
28 changes: 28 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,31 @@
- regexp: "^.?SOLR_OPTS="
line: 'SOLR_OPTS="{{ solr_opts }}"'
notify: restart solr
when: solr_jetty_host == '127.0.0.1'

- name: Apply Solr configuration changes solr >= 9.3.0.
lineinfile:
dest: "{{ solr_config_file }}"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
mode: 0644
with_items:
- regexp: "^.?SOLR_JAVA_MEM="
line: 'SOLR_JAVA_MEM="-Xms{{ solr_xms }} -Xmx{{ solr_xmx }}"'
- regexp: "^SOLR_PORT="
line: 'SOLR_PORT="{{ solr_port }}"'
- regexp: "^.?SOLR_TIMEZONE="
line: 'SOLR_TIMEZONE="{{ solr_timezone }}"'
- regexp: "^.?SOLR_OPTS="
line: 'SOLR_OPTS="{{ solr_opts }}"'
- regexp: "^.?SOLR_JETTY_HOST="
line: 'SOLR_JETTY_HOST="{{ solr_jetty_host }}"'
register: solr_config
when: solr_jetty_host != '127.0.0.1'

- name: Restart solr to load new configuration
service:
name: solr
state: restarted
when: solr_config.changed
32 changes: 32 additions & 0 deletions tasks/cores-post93.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: Check current list of Solr cores.
uri:
url: http://{{ solr_jetty_host }}:{{ solr_port }}/solr/admin/cores
return_content: true
register: solr_cores_current
check_mode: false

- name: Ensure Solr conf directories exist.
file:
path: "{{ solr_home }}/data/{{ item }}/conf"
state: directory
owner: "{{ solr_user }}"
group: "{{ solr_group }}"
recurse: true
mode: 0755
when: "item not in solr_cores_current.content"
with_items: "{{ solr_cores }}"

- name: Ensure core configuration directories exist.
command: "cp -r {{ solr_default_core_path }} {{ solr_home }}/data/{{ item }}/"
when: "item not in solr_cores_current.content"
with_items: "{{ solr_cores }}"
become: true
become_user: "{{ solr_user }}"

- name: Create configured cores.
command: "{{ solr_install_path }}/bin/solr create -c {{ item }} -h {{ solr_jetty_host }} -p {{ solr_port }}"
when: "item not in solr_cores_current.content"
with_items: "{{ solr_cores }}"
become: true
become_user: "{{ solr_user }}"
15 changes: 14 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
- import_tasks: checks.yml

- import_tasks: user.yml
when: solr_create_user

Expand Down Expand Up @@ -64,6 +66,17 @@

# Create cores, if any are configured.
- include_tasks: cores.yml
when: "solr_cores and solr_version.split('.')[0] >= '5'"
when:
- solr_cores
- solr_version.split('.')[0] >= '5'
- solr_jetty_host == '127.0.0.1'

# Create cores also when solr is listening on custom network interface. Just for solr 9.3.0 and higher.
- include_tasks: cores-post93.yml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the requirement for a separate cores task file here? I don't think that was explicitly explained but it includes a bit of duplicate code.

when:
- solr_cores
- solr_version is version('9.3.0' ,'>=')
- solr_jetty_host != '127.0.0.1'


- include_tasks: trim-fat.yml