Merge pull request #56 from gingerwizard/master
Restart on Change, Cleanup + better restart
This commit is contained in:
commit
0fd268ca3f
11 changed files with 59 additions and 26 deletions
|
|
@ -4,6 +4,7 @@ es_version: "2.1.0"
|
||||||
es_version_lock: false
|
es_version_lock: false
|
||||||
es_use_repository: true
|
es_use_repository: true
|
||||||
es_start_service: true
|
es_start_service: true
|
||||||
|
es_restart_on_change: true
|
||||||
es_plugins_reinstall: false
|
es_plugins_reinstall: false
|
||||||
es_scripts: false
|
es_scripts: false
|
||||||
es_templates: false
|
es_templates: false
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
- name: restart elasticsearch
|
- name: restart elasticsearch
|
||||||
service: name={{instance_init_script | basename}} state=restarted enabled=yes
|
service: name={{instance_init_script | basename}} state=restarted enabled=yes
|
||||||
when: es_start_service and (not elasticsearch_started.changed or (plugin_installed is defined and plugin_installed.changed))
|
when: es_restart_on_change and es_start_service and (not elasticsearch_started.changed or (plugin_installed is defined and plugin_installed.changed) or elasticsearch_install.changed)
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,7 @@
|
||||||
#Relies on elasticsearch distribution installing a serviced script to determine whether one should be copied.
|
#Relies on elasticsearch distribution installing a serviced script to determine whether one should be copied.
|
||||||
|
|
||||||
|
|
||||||
- stat: path={{sysd_script}}
|
- set_fact: use_system_d={{(ansible_distribution == 'Debian' and ansible_distribution_version | version_compare('8', '>=')) or (ansible_distribution == 'CentOS' and ansible_distribution_version | version_compare('7', '>=')) or (ansible_distribution == 'Ubuntu' and ansible_distribution_version | version_compare('15', '>=')) }}
|
||||||
register: systemd_service
|
|
||||||
|
|
||||||
- set_fact: use_system_d={{systemd_service.stat.exists and ((ansible_distribution == 'Debian' and ansible_distribution_version | version_compare('8', '>=')) or (ansible_distribution == 'CentOS' and ansible_distribution_version | version_compare('7', '>=')) or (ansible_distribution == 'Ubuntu' and ansible_distribution_version | version_compare('15', '>='))) }}
|
|
||||||
|
|
||||||
- set_fact: instance_sysd_script={{sysd_script | dirname }}/{{es_instance_name}}_{{sysd_script | basename}}
|
- set_fact: instance_sysd_script={{sysd_script | dirname }}/{{es_instance_name}}_{{sysd_script | basename}}
|
||||||
when: use_system_d
|
when: use_system_d
|
||||||
|
|
@ -81,3 +78,17 @@
|
||||||
notify: restart elasticsearch
|
notify: restart elasticsearch
|
||||||
|
|
||||||
#Clean up un-wanted package scripts to avoid confusion
|
#Clean up un-wanted package scripts to avoid confusion
|
||||||
|
|
||||||
|
- name: Delete Default Init
|
||||||
|
file: dest=/etc/init.d/elasticsearch state=absent
|
||||||
|
|
||||||
|
- name: Delete Default Environment File
|
||||||
|
file: dest=/etc/default/elasticsearch state=absent
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Delete Default Environment File
|
||||||
|
file: dest=/etc/sysconfig/elasticsearch state=absent
|
||||||
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
|
- name: Delete Default Sysconfig File
|
||||||
|
file: dest=/usr/lib/systemd/system/elasticsearch.service state=absent
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,19 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
|
#es_plugins_reinstall will be set to true if elasticsearch_install.changed i.e. we have changed ES version
|
||||||
|
- set_fact: es_plugins_reinstall=true
|
||||||
|
when: elasticsearch_install.changed
|
||||||
|
|
||||||
|
#List currently installed plugins
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#This needs to removed installed plugins not those listed
|
||||||
- name: Remove elasticsearch plugins
|
- name: Remove elasticsearch plugins
|
||||||
command: "{{es_home}}/bin/plugin remove {{ item.plugin }} --silent"
|
command: "{{es_home}}/bin/plugin remove {{ item.plugin }} --silent"
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
with_items: es_plugins
|
with_items: es_plugins
|
||||||
when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' ) and es_plugins_reinstall
|
when: es_plugins_reinstall
|
||||||
notify: restart elasticsearch
|
notify: restart elasticsearch
|
||||||
environment:
|
environment:
|
||||||
CONF_DIR: "{{ conf_dir }}"
|
CONF_DIR: "{{ conf_dir }}"
|
||||||
|
|
|
||||||
6
tasks/elasticsearch-service.yml
Normal file
6
tasks/elasticsearch-service.yml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
# Make sure the service is started, and restart if necessary
|
||||||
|
- name: Start elasticsearch service
|
||||||
|
service: name={{instance_init_script | basename}} state=started enabled=yes
|
||||||
|
when: es_start_service
|
||||||
|
register: elasticsearch_started
|
||||||
|
|
||||||
|
|
@ -8,7 +8,10 @@
|
||||||
|
|
||||||
- debug: msg="Node configuration {{ es_config }} "
|
- debug: msg="Node configuration {{ es_config }} "
|
||||||
|
|
||||||
# Install OS specific elasticsearch - this can be abbreviated in version 2.0.0
|
#- name: Include specific Elasticsearch
|
||||||
|
# include: "elasticsearch-{{ansible_os_family}}.yml"
|
||||||
|
|
||||||
|
#Install OS specific elasticsearch - this can be abbreviated in version 2.0.0
|
||||||
- name: Include specific Elasticsearch
|
- name: Include specific Elasticsearch
|
||||||
include: elasticsearch-Debian.yml
|
include: elasticsearch-Debian.yml
|
||||||
when: ansible_os_family == 'Debian'
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
@ -16,17 +19,3 @@
|
||||||
- name: Include specific Elasticsearch
|
- name: Include specific Elasticsearch
|
||||||
include: elasticsearch-RedHat.yml
|
include: elasticsearch-RedHat.yml
|
||||||
when: ansible_os_family == 'RedHat'
|
when: ansible_os_family == 'RedHat'
|
||||||
|
|
||||||
#Configuration file for elasticsearch
|
|
||||||
- name: Elasticsearch configuration
|
|
||||||
include: elasticsearch-config.yml
|
|
||||||
|
|
||||||
# Make sure the service is started, and restart if necessary
|
|
||||||
- name: Start elasticsearch service
|
|
||||||
service: name={{instance_init_script | basename}} state=started enabled=yes
|
|
||||||
when: es_start_service
|
|
||||||
register: elasticsearch_started
|
|
||||||
|
|
||||||
- name: Restart elasticsearch service if new version installed
|
|
||||||
service: name={{instance_init_script | basename}} state=restarted enabled=yes
|
|
||||||
when: es_start_service and elasticsearch_install.changed and not elasticsearch_started.changed
|
|
||||||
|
|
@ -5,10 +5,12 @@
|
||||||
include_vars: "{{ansible_os_family}}.yml"
|
include_vars: "{{ansible_os_family}}.yml"
|
||||||
- include: java.yml
|
- include: java.yml
|
||||||
- include: elasticsearch.yml
|
- include: elasticsearch.yml
|
||||||
- include: elasticsearch-plugins.yml
|
- include: elasticsearch-config.yml
|
||||||
when: es_plugins is defined
|
|
||||||
- include: elasticsearch-scripts.yml
|
- include: elasticsearch-scripts.yml
|
||||||
when: es_scripts
|
when: es_scripts
|
||||||
|
- include: elasticsearch-plugins.yml
|
||||||
|
when: es_plugins is defined
|
||||||
|
- include: elasticsearch-service.yml
|
||||||
- include: elasticsearch-templates.yml
|
- include: elasticsearch-templates.yml
|
||||||
when: es_templates
|
when: es_templates
|
||||||
- meta: flush_handlers
|
- meta: flush_handlers
|
||||||
|
|
@ -47,5 +47,21 @@ shared_examples 'standard::init' do |es_version|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe file('/etc/init.d/elasticsearch') do
|
||||||
|
it { should_not exist }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe file('/etc/default/elasticsearch') do
|
||||||
|
it { should_not exist }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe file('/etc/sysconfig/elasticsearch') do
|
||||||
|
it { should_not exist }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe file('/usr/lib/systemd/system/elasticsearch.service') do
|
||||||
|
it { should_not exist }
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
---
|
---
|
||||||
java: "openjdk-7-jre-headless"
|
java: "openjdk-7-jre-headless"
|
||||||
default_file: "/etc/default/elasticsearch"
|
default_file: "/etc/default/elasticsearch"
|
||||||
init_script: "/etc/init.d/elasticsearch"
|
|
||||||
es_home: "/usr/share/elasticsearch"
|
es_home: "/usr/share/elasticsearch"
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
---
|
---
|
||||||
java: "java-1.8.0-openjdk.x86_64"
|
java: "java-1.8.0-openjdk.x86_64"
|
||||||
default_file: "/etc/sysconfig/elasticsearch"
|
default_file: "/etc/sysconfig/elasticsearch"
|
||||||
init_script: "/etc/init.d/elasticsearch"
|
|
||||||
es_home: "/usr/share/elasticsearch"
|
es_home: "/usr/share/elasticsearch"
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
---
|
---
|
||||||
es_package_url: "https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch"
|
es_package_url: "https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch"
|
||||||
es_conf_dir: "/etc/elasticsearch"
|
es_conf_dir: "/etc/elasticsearch"
|
||||||
sysd_script: "/usr/lib/systemd/system/elasticsearch.service"
|
sysd_script: "/usr/lib/systemd/system/elasticsearch.service"
|
||||||
|
init_script: "/etc/init.d/elasticsearch"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue