Skip to content

Commit 86f2bd9

Browse files
author
Dale McDiarmid
committed
2.0 Support + Plugin Directory Support + Supporting Tests + Defaults Change
1 parent 1034995 commit 86f2bd9

40 files changed

+297
-113
lines changed

.kitchen.yml

+47-5
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,66 @@ platforms:
5656
use_sudo: false
5757

5858
suites:
59-
- name: standard
59+
- name: standard-2x
6060
provisioner:
6161
playbook: test/integration/standard.yml
6262
run_list:
6363
attributes:
64-
- name: package
64+
- name: package-2x
6565
run_list:
6666
attributes:
67+
extra_vars:
68+
es_plugins:
69+
- plugin: lmenezes/elasticsearch-kopf
70+
version: master
71+
- plugin: license
72+
- plugin: marvel-agent
6773
provisioner:
6874
playbook: test/integration/package.yml
69-
- name: config
75+
- name: config-2x
7076
run_list:
7177
attributes:
7278
provisioner:
7379
playbook: test/integration/config.yml
74-
- name: multi
80+
- name: multi-2x
7581
run_list:
7682
attributes:
7783
provisioner:
7884
playbook: test/integration/multi.yml
79-
85+
- name: standard-1x
86+
provisioner:
87+
playbook: test/integration/standard.yml
88+
run_list:
89+
attributes:
90+
extra_vars:
91+
es_major_version: 1.7
92+
es_version: 1.7.3
93+
- name: package-1x
94+
run_list:
95+
attributes:
96+
extra_vars:
97+
es_major_version: 1.7
98+
es_version: 1.7.3
99+
es_plugins:
100+
- plugin: lmenezes/elasticsearch-kopf
101+
version: master
102+
- plugin: elasticsearch/marvel
103+
version: latest
104+
provisioner:
105+
playbook: test/integration/package.yml
106+
- name: config-1x
107+
run_list:
108+
attributes:
109+
extra_vars:
110+
es_major_version: 1.7
111+
es_version: 1.7.3
112+
provisioner:
113+
playbook: test/integration/config.yml
114+
- name: multi-1x
115+
run_list:
116+
attributes:
117+
extra_vars:
118+
es_major_version: 1.7
119+
es_version: 1.7.3
120+
provisioner:
121+
playbook: test/integration/multi.yml

defaults/main.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
es_major_version: "1.7"
3-
es_version: "1.7.3"
2+
es_major_version: "2.x"
3+
es_version: "2.1.0"
44
es_version_lock: false
55
es_use_repository: true
66
es_start_service: true
@@ -14,4 +14,5 @@ es_config: {}
1414
es_pid_dir: "/var/run/elasticsearch"
1515
es_data_dir: "/var/lib/elasticsearch"
1616
es_log_dir: "/var/log/elasticsearch"
17-
es_work_dir: "/tmp/elasticsearch"
17+
es_work_dir: "/tmp/elasticsearch"
18+
es_plugin_dir: "/usr/share/elasticsearch/plugins"

handlers/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
- name: restart elasticsearch
33
service: name={{instance_init_script | basename}} state=restarted enabled=yes
4-
when: es_start_service and not elasticsearch_started.changed
4+
when: es_start_service and (not elasticsearch_started.changed or plugin_installed.changed)

tasks/checkParameters.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
- fail: msg="es_instance_name must be specified"
44
when: es_instance_name is not defined
55

6-
- set_fact: multi_cast={{ (es_version | version_compare('2.0', '<') and es_config['discovery.zen.ping.multicast.enabled'] is not defined) or es_config['discovery.zen.ping.multicast.enabled']}}
6+
- set_fact: multi_cast={{ (es_version | version_compare('2.0', '<') and es_config['discovery.zen.ping.multicast.enabled'] is not defined) or (es_config['discovery.zen.ping.multicast.enabled'] is defined and es_config['discovery.zen.ping.multicast.enabled'])}}
77

8-
- fail: msg="Parameter 'http.port' must be defined when multicast is disabled"
8+
- debug: msg="WARNING - It is recommended you specify the parameter 'http.port' when multicast is disabled"
99
when: not multi_cast and es_config['http.port'] is not defined
1010

11-
- fail: msg="Parameter 'transport.tcp.port' must be defined when multicast is disabled"
11+
- debug: msg="WARNING - It is recommended you specify the parameter 'transport.tcp.port' when multicast is disabled"
1212
when: not multi_cast and es_config['transport.tcp.port'] is not defined
1313

14-
- fail: msg="Parameter 'discovery.zen.ping.unicast.hosts' must be defined when multicast is disabled"
14+
- debug: msg="WARNING - It is recommended you specify the parameter 'discovery.zen.ping.unicast.hosts' when multicast is disabled"
1515
when: not multi_cast and es_config['discovery.zen.ping.unicast.hosts'] is not defined
1616

1717
#If the user attempts to lock memory they must specify a heap size

tasks/elasticsearch-config.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#For directories we also use the {{inventory_hostname}}-{{ es_instance_name }} - this helps if we have a shared SAN.
1414

15-
- set_fact: pid_dir={{es_pid_dir}}/{{inventory_hostname}}-{{ es_instance_name }}
15+
- set_fact: pid_dir={{ es_pid_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
1616

1717
- set_fact: data_dir={{ es_data_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
1818

@@ -34,11 +34,14 @@
3434
file: state=directory path={{ log_dir }} owner={{ es_user }} group={{ es_group }}
3535

3636
- name: Create Config Directory
37-
file: path={{ instance_config_directory }} state=directory owner={{ es_user }} group={{ es_group }}
37+
file: path={{ conf_dir }} state=directory owner={{ es_user }} group={{ es_group }}
38+
39+
- name: Create Plugin Directory
40+
file: state=directory path={{ plugin_dir }} owner={{ es_user }} group={{ es_group }}
3841

3942
#Copy the config template
4043
- name: Copy Configuration File
41-
template: src=elasticsearch.yml.j2 dest={{instance_config_directory}}/elasticsearch.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
44+
template: src=elasticsearch.yml.j2 dest={{conf_dir}}/elasticsearch.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
4245
notify: restart elasticsearch
4346

4447
#Copy the instance specific default file
@@ -64,5 +67,5 @@
6467

6568
#Copy the logging.yml
6669
- name: Copy Logging.yml File for Instance
67-
template: src=logging.yml.j2 dest={{instance_config_directory}}/logging.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
70+
template: src=logging.yml.j2 dest={{conf_dir}}/logging.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
6871
notify: restart elasticsearch

tasks/elasticsearch-plugins.yml

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
---
2+
23
- name: Remove elasticsearch plugins
3-
command: /usr/share/elasticsearch/bin/plugin --remove {{ item.plugin }} --silent
4+
command: "{{es_home}}/bin/plugin remove {{ item.plugin }} --silent"
45
ignore_errors: yes
56
with_items: es_plugins
67
when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' ) and es_plugins_reinstall
8+
notify: restart elasticsearch
9+
environment:
10+
CONF_DIR: "{{ conf_dir }}"
711

812
- name: Install elasticsearch plugins
913
#debug: var=item
10-
command: /usr/share/elasticsearch/bin/plugin --install {{ item.plugin }}/{{ item.version }} --silent
11-
register: command_result
12-
failed_when: "'Failed to install' in command_result.stderr"
13-
changed_when: command_result.rc == 0
14+
command: "{{es_home}}/bin/plugin install {{ item.plugin }}{% if item.version is defined and item.version != '' %}/{{ item.version }}{% endif %} --silent"
15+
register: plugin_installed
16+
failed_when: "'Failed to install' in plugin_installed.stderr"
17+
changed_when: plugin_installed.rc == 0
1418
with_items: es_plugins
15-
when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' )
19+
when: ansible_os_family == 'RedHat' or ansible_os_family == 'Debian'
20+
notify: restart elasticsearch
21+
environment:
22+
CONF_DIR: "{{ conf_dir }}"
23+
24+
#Set permissions on plugins directory
25+
- name: Set Plugin Directory Permissions
26+
file: state=directory path={{ plugin_dir }} owner={{ es_user }} group={{ es_group }} recurse=yes

tasks/elasticsearch.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
- set_fact: instance_default_file={{default_file | dirname}}/{{es_instance_name}}_{{default_file | basename}}
44
- set_fact: instance_init_script={{init_script | dirname }}/{{es_instance_name}}_{{init_script | basename}}
5-
- set_fact: instance_config_directory={{ es_conf_dir }}/{{es_instance_name}}
5+
- set_fact: conf_dir={{ es_conf_dir }}/{{es_instance_name}}
6+
- set_fact: plugin_dir={{ es_plugin_dir }}/{{es_instance_name}}
67
- set_fact: m_lock_enabled={{ es_config['bootstrap.mlockall'] is defined and es_config['bootstrap.mlockall'] == True }}
78

89
- debug: msg="Node configuration {{ es_config }} "
@@ -20,7 +21,6 @@
2021
- name: Elasticsearch configuration
2122
include: elasticsearch-config.yml
2223

23-
2424
# Make sure the service is started, and restart if necessary
2525
- name: Start elasticsearch service
2626
service: name={{instance_init_script | basename}} state=started enabled=yes

templates/elasticsearch.j2

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
ES_HOME={{es_home}}
77

88
# Elasticsearch configuration directory
9-
CONF_DIR={{instance_config_directory}}
10-
11-
# Elasticsearch configuration file
12-
CONF_FILE={{instance_config_directory}}/elasticsearch.yml
9+
CONF_DIR={{conf_dir}}
1310

1411
# Elasticsearch data directory
1512
DATA_DIR={{data_dir}}

templates/elasticsearch.repo

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[elasticsearch-{{ es_major_version }}]
2-
name=Elasticsearch repository for {{ es_major_version }}.x packages
2+
name=Elasticsearch repository for {{ es_major_version }} packages
33
baseurl=http://packages.elastic.co/elasticsearch/{{ es_major_version }}/centos
44
gpgcheck=1
55
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch

templates/elasticsearch.yml.j2

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ node.name: {{inventory_hostname}}-{{es_instance_name}}
1414
#################################### Paths ####################################
1515

1616
# Path to directory containing configuration (this file and logging.yml):
17-
path.conf: {{ instance_config_directory }}
17+
path.conf: {{ conf_dir }}
1818

1919
path.data: {{ data_dir }}
2020

2121
path.work: {{ work_dir }}
2222

23-
path.logs: {{ log_dir }}
23+
path.logs: {{ log_dir }}
24+
25+
path.plugins: {{ plugin_dir }}

templates/init/debian/elasticsearch.j2

+29-36
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ DESC="Elasticsearch Server - {{es_config['node.name']}}"
2626
{% else %}
2727
DESC="Elasticsearch Server - {{es_instance_name}}"
2828
{% endif %}
29+
2930
DEFAULT=/etc/default/$NAME
3031

3132
if [ `id -u` -ne 0 ]; then
@@ -40,23 +41,13 @@ if [ -r /etc/default/rcS ]; then
4041
. /etc/default/rcS
4142
fi
4243

44+
4345
# The following variables can be overwritten in $DEFAULT
4446

4547
# Run Elasticsearch as this user ID and group ID
4648
ES_USER=elasticsearch
4749
ES_GROUP=elasticsearch
4850

49-
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not defined in $DEFAULT)
50-
JDK_DIRS="/usr/lib/jvm/java-8-oracle/ /usr/lib/jvm/j2sdk1.8-oracle/ /usr/lib/jvm/jdk-7-oracle-x64 /usr/lib/jvm/java-7-oracle /usr/lib/jvm/j2sdk1.7-oracle/ /usr/lib/jvm/java-7-openjdk /usr/lib/jvm/java-7-openjdk-amd64/ /usr/lib/jvm/java-7-openjdk-armhf /usr/lib/jvm/java-7-openjdk-i386/ /usr/lib/jvm/default-java"
51-
52-
# Look for the right JVM to use
53-
for jdir in $JDK_DIRS; do
54-
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
55-
JAVA_HOME="$jdir"
56-
fi
57-
done
58-
export JAVA_HOME
59-
6051
# Directory where the Elasticsearch binary distribution resides
6152
ES_HOME=/usr/share/$NAME
6253

@@ -85,15 +76,9 @@ LOG_DIR=/var/log/$NAME
8576
# Elasticsearch data directory
8677
DATA_DIR=/var/lib/$NAME
8778

88-
# Elasticsearch work directory
89-
WORK_DIR=/tmp/$NAME
90-
9179
# Elasticsearch configuration directory
9280
CONF_DIR=/etc/$NAME
9381

94-
# Elasticsearch configuration file (elasticsearch.yml)
95-
CONF_FILE=$CONF_DIR/elasticsearch.yml
96-
9782
# Maximum number of VMA (Virtual Memory Areas) a process can own
9883
MAX_MAP_COUNT=262144
9984

@@ -110,15 +95,23 @@ if [ -f "$DEFAULT" ]; then
11095
. "$DEFAULT"
11196
fi
11297

98+
# CONF_FILE setting was removed
99+
if [ ! -z "$CONF_FILE" ]; then
100+
echo "CONF_FILE setting is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed."
101+
exit 1
102+
fi
103+
113104
# Define other required variables
114105
PID_FILE="$PID_DIR/$NAME.pid"
115106
DAEMON=$ES_HOME/bin/elasticsearch
116-
DAEMON_OPTS="-d -p $PID_FILE --default.config=$CONF_FILE --default.path.home=$ES_HOME --default.path.logs=$LOG_DIR --default.path.data=$DATA_DIR --default.path.work=$WORK_DIR --default.path.conf=$CONF_DIR"
107+
DAEMON_OPTS="-d -p $PID_FILE --default.path.home=$ES_HOME --default.path.logs=$LOG_DIR --default.path.data=$DATA_DIR --default.path.conf=$CONF_DIR"
117108

118109
export ES_HEAP_SIZE
119110
export ES_HEAP_NEWSIZE
120111
export ES_DIRECT_SIZE
121112
export ES_JAVA_OPTS
113+
export ES_GC_LOG_FILE
114+
export JAVA_HOME
122115

123116
# Check DAEMON exists
124117
test -x $DAEMON || exit 0
@@ -155,15 +148,15 @@ case "$1" in
155148
fi
156149

157150
# Prepare environment
158-
mkdir -p "$LOG_DIR" "$DATA_DIR" "$WORK_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR" "$WORK_DIR"
151+
mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR"
159152

160-
# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
161-
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
162-
mkdir -p "$PID_DIR" && chown "$ES_USER":"$ES_GROUP" "$PID_DIR"
163-
fi
164-
if [ -n "$PID_FILE" ] && [ ! -e "$PID_FILE" ]; then
165-
touch "$PID_FILE" && chown "$ES_USER":"$ES_GROUP" "$PID_FILE"
166-
fi
153+
# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
154+
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
155+
mkdir -p "$PID_DIR" && chown "$ES_USER":"$ES_GROUP" "$PID_DIR"
156+
fi
157+
if [ -n "$PID_FILE" ] && [ ! -e "$PID_FILE" ]; then
158+
touch "$PID_FILE" && chown "$ES_USER":"$ES_GROUP" "$PID_FILE"
159+
fi
167160

168161
if [ -n "$MAX_OPEN_FILES" ]; then
169162
ulimit -n $MAX_OPEN_FILES
@@ -178,10 +171,9 @@ case "$1" in
178171
fi
179172

180173
# Start Daemon
181-
start-stop-daemon --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
174+
start-stop-daemon -d $ES_HOME --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
182175
return=$?
183-
if [ $return -eq 0 ]
184-
then
176+
if [ $return -eq 0 ]; then
185177
i=0
186178
timeout=10
187179
# Wait for the process to be properly started before exiting
@@ -194,17 +186,18 @@ case "$1" in
194186
exit 1
195187
fi
196188
done
197-
else
198-
log_end_msg $return
199189
fi
200-
;;
190+
log_end_msg $return
191+
exit $return
192+
;;
201193
stop)
202194
log_daemon_msg "Stopping $DESC"
203195

204-
if [ -f "$PID_FILE" ]; then
196+
if [ -f "$PID_FILE" ]; then
205197
start-stop-daemon --stop --pidfile "$PID_FILE" \
206198
--user "$ES_USER" \
207-
--retry=TERM/20/KILL/5 >/dev/null
199+
--quiet \
200+
--retry forever/TERM/20 > /dev/null
208201
if [ $? -eq 1 ]; then
209202
log_progress_msg "$DESC is not running but pid file exists, cleaning up"
210203
elif [ $? -eq 3 ]; then
@@ -220,7 +213,7 @@ case "$1" in
220213
;;
221214
status)
222215
status_of_proc -p $PID_FILE elasticsearch elasticsearch && exit 0 || exit $?
223-
;;
216+
;;
224217
restart|force-reload)
225218
if [ -f "$PID_FILE" ]; then
226219
$0 stop
@@ -234,4 +227,4 @@ case "$1" in
234227
;;
235228
esac
236229

237-
exit 0
230+
exit 0

0 commit comments

Comments
 (0)