Add a systemd unit.

This commit is contained in:
Andrea Dell'Amico 2024-11-25 18:04:26 +01:00
parent b4391a4064
commit f9ec6f5267
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
4 changed files with 101 additions and 39 deletions

View File

@ -1,7 +1,7 @@
---
# solr
solr_install: True
solr_version: 7.4.0
solr_version: 9.7.0
solr_http_port: 8983
solr_service: -solr
solr_config_name: hindex

View File

@ -1,6 +1,15 @@
---
- name: solr restart
service: name=solr state=restarted
- name: Solr restart
ansible.builtin.service:
name: solr
state: restarted
- name: Restart Solr prometheus exporter
service: name=solr_prometheus_exporter state=restarted enabled=yes
ansible.builtin.service:
name: solr_prometheus_exporter
state: restarted
enabled: true
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true

View File

@ -1,5 +1,10 @@
---
- block:
- name: Manage the SOLR installation
become: true
become_user: root
when: solr_install
tags: solr
block:
- name: Create a solr user
user: name={{ solr_user }} home={{ solr_base_dir }} createhome=yes shell=/bin/bash system=yes
@ -39,31 +44,47 @@
with_items:
- solr.xml
- zoo.cfg
notify: solr restart
notify: Solr restart
tags: [ 'solr', 'solr_default', 'solr_conf' ]
- name: copy extra libraries
shell: cd {{ solr_server_dir }}; cp -u {{ item }} {{ solr_data_dir }}/lib
with_items: '{{ solr_jar_files }}'
- name: install the solr init script
template: src=solr dest=/etc/init.d/solr mode=0755 owner=root group=root
- name: Install the solr default
template: src=solr-default.j2 dest=/etc/default/solr.in.sh mode=0644 owner=root group=root
notify: solr restart
notify: Solr restart
tags: [ 'solr', 'solr_default', 'solr_conf' ]
- name: install the solr init script
template: src=solr dest=/etc/init.d/solr mode=0755 owner=root group=root
when: ansible_service_mgr != 'systemd'
- name: Install the SOLR systemd unit
ansible.builtin.template:
src: solr.service.j2
dest: /etc/systemd/system/solr.service
owner: root
group: root
mode: "0644"
tags: ['solr', 'solr_default', 'solr_conf', 'solr_init']
when: ansible_service_mgr == 'systemd'
notify: Reload systemd
- name: Reload the systemd service
ansible.builtin.meta: flush_handlers
- name: Start and enable the solr service
service: name=solr state=started enabled=yes
ignore_errors: True
ignore_errors: true
become: True
- name: Manage the installation of the Solr metrics exporter
become: true
become_user: root
when: solr_install
tags: solr
- block:
when:
- solr_install
- solr_prometheus_exporter
tags: ['solr', 'solr_prometheus', 'solr_prometheus_exporter']
block:
- name: Create the Solr prometheus exporter conf directory
file: dest={{ solr_prometheus_conf_dir }} state=directory mode=0755
@ -83,11 +104,3 @@
- name: Ensure that Solr prometheus exporter is started and enabled
service: name=solr_prometheus_exporter state=started enabled=yes
become: True
become_user: root
when:
- solr_install
- solr_prometheus_exporter
tags: [ 'solr', 'solr_prometheus', 'solr_prometheus_exporter' ]

40
templates/solr.service.j2 Normal file
View File

@ -0,0 +1,40 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[Unit]
Description=Apache Solr
After=network.target
StartLimitIntervalSec=300
StartLimitBurst=5
[Service]
Type=forking
User=solr
Environment=SOLR_INCLUDE=/etc/default/solr.in.sh
Environment=RUNAS=solr
ExecStart=${SOLR_INSTALL_DIR}/bin/solr start
ExecStop=${SOLR_INSTALL_DIR}/bin/solr stop
Restart=on-failure
RestartSec=3s
TimeoutSec=180s
PrivateTmp=true
LimitNOFILE=65000
LimitNPROC=65000
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target