Merge pull request #35 from gingerwizard/master

2.0 support
This commit is contained in:
gingerwizard 2015-12-18 12:41:12 +01:00
commit 14cb6a114c
42 changed files with 406 additions and 154 deletions

View file

@ -56,24 +56,77 @@ platforms:
use_sudo: false
suites:
- name: standard
- name: standard-2x
provisioner:
playbook: test/integration/standard.yml
run_list:
attributes:
- name: package
- name: package-2x
run_list:
attributes:
extra_vars:
es_plugins:
- plugin: lmenezes/elasticsearch-kopf
version: master
- plugin: license
- plugin: marvel-agent
provisioner:
playbook: test/integration/package.yml
- name: config
- name: config-2x
run_list:
attributes:
provisioner:
playbook: test/integration/config.yml
- name: multi
- name: multi-2x
run_list:
attributes:
extra_vars:
es_plugins:
- plugin: lmenezes/elasticsearch-kopf
version: master
- plugin: license
- plugin: marvel-agent
provisioner:
playbook: test/integration/multi.yml
- name: standard-1x
provisioner:
playbook: test/integration/standard.yml
run_list:
attributes:
extra_vars:
es_major_version: 1.7
es_version: 1.7.3
- name: package-1x
run_list:
attributes:
extra_vars:
es_major_version: 1.7
es_version: 1.7.3
es_plugins:
- plugin: lmenezes/elasticsearch-kopf
version: master
- plugin: elasticsearch/marvel
version: latest
provisioner:
playbook: test/integration/package.yml
- name: config-1x
run_list:
attributes:
extra_vars:
es_major_version: 1.7
es_version: 1.7.3
provisioner:
playbook: test/integration/config.yml
- name: multi-1x
run_list:
attributes:
extra_vars:
es_major_version: 1.7
es_version: 1.7.3
es_plugins:
- plugin: lmenezes/elasticsearch-kopf
version: master
- plugin: elasticsearch/marvel
version: latest
provisioner:
playbook: test/integration/multi.yml

View file

@ -1,6 +1,6 @@
# ansible-elasticsearch
Ansible playbook / roles / tasks for Elasticsearch. Currently it will work on Debian and RedHat based linux systems. Tested platforms are:
Ansible role for Elasticsearch. Currently this works on Debian and RedHat based linux systems. Tested platforms are:
* Ubuntu 1404
* Debian 7
@ -23,7 +23,8 @@ mkdir -p roles
ln -s /my/repos/ansible-elasticsearch ./roles/elasticsearch
```
Then create your playbook yaml adding the role elasticsearch. By default, the user is only required to specify a unique es_instance_name per role application.
Then create your playbook yaml adding the role elasticsearch. By default, the user is only required to specify a unique es_instance_name per role application. This should be unique per node.
The application of the elasticsearch role results in the installation of a node on a host.
The simplest configuration therefore consists of:
@ -36,12 +37,16 @@ The simplest configuration therefore consists of:
vars:
```
The above installs a single node 'node1' on the hosts 'localhost'.
### Basic Elasticsearch Configuration
All Elasticsearch configuration parameters are supported. This is achieved using a configuration map parameter 'es_config' which is serialized into the elasticsearch.yml file.
The use of a map ensures the Ansible playbook does not need to be updated to reflect new/deprecated/plugin configuration parameters.
In addition to the es_config map, several other parameters are supported for additional functions e.g. script installation. These can be found in the role's defaults/main.yml file.
The following illustrates applying configuration parameters to an Elasticsearch instance.
The following illustrates applying configuration parameters to an Elasticsearch instance. By default, Elasticsearch 2.1.0 is installed.
```
- name: Elasticsearch with custom configuration
@ -55,17 +60,20 @@ The following illustrates applying configuration parameters to an Elasticsearch
es_version_lock: false
es_heap_size: 1g
```
`
The role utilises Elasticsearch version defaults. Multicast is therefore enabled for 1.x and disabled for 2.x (plugin required in 2.x). If using 1.x it is strongly recommended you disable
multicast and specify the required uni-cast settings for a production environment.
When not utilizing multicast, the following should be set to ensure a successful cluster forms.
* ```es_config['http.port']``` - the http port for the node
* ```es_config['transport.tcp.port']``` - the transport port for the node
* ```es_config['discovery.zen.ping.unicast.hosts']``` - the unicast discovery list, in the comma separated format "<host>:<port>,<host>:<port>" (typically the clusters dedicated masters)
* ```es_config['network.host']``` - sets both network.bind_host and network.publish_host to the same host value. The network.bind_host setting allows to control the host different network components will bind on.
The network.publish_host setting allows to control the host the node will publish itself within the cluster so other nodes will be able to connect to it.
The playbook utilises Elasticsearch version defaults. By default, therefore, multicast is enabled for 1.x. If disabled, the user user is required to specify the following additional parameters:
1. es_config['http.port'] - the http port for the node
2. es_config['transport.tcp.port'] - the transport port for the node
3. es_config['discovery.zen.ping.unicast.hosts'] - the unicast discovery list, in the comma separated format "<host>:<port>,<host>:<port>" (typically the clusters dedicated masters)
If set to true, the ports will be auto defined and node discovery will be performed using multicast.
See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html for further details on default binding behaviour and available options.
The role makes no attempt to enforce the setting of these are requires users to specify them appropriately. IT is recommended master nodes are listed and thus deployed first where possible.
A more complex example:
@ -87,32 +95,23 @@ A more complex example:
es_start_service: false
es_plugins_reinstall: false
es_plugins:
- plugin: elasticsearch/elasticsearch-cloud-aws
version: 2.5.0
- plugin: elasticsearch/marvel
version: latest
- plugin: elasticsearch/license
version: latest
- plugin: elasticsearch/shield
version: latest
- plugin: elasticsearch/elasticsearch-support-diagnostics
version: latest
- plugin: license
- plugin: marvel-agent
- plugin: lmenezes/elasticsearch-kopf
version: master
```
The application of a role results in the installation of a node on a host. Multiple roles equates to multiple nodes for a single host.
### Multi Node Server Installations
In any multi node cluster configuration it is recommened the user list the master eligble roles first - especially if these are used a unicast hosts off which other nodes are 'booted'
The application of the elasticsearch role results in the installation of a node on a host. Specifying the role multiple times for a host therefore results in the installation of multiple nodes for the host.
An example of a two server deployment, each with 1 node on one server and 2 nodes on another. The first server holds the master and is thus declared first. Whilst not mandatory, this is
recommended in any multi node cluster configuration.
An example of a two server deployment, each with 1 node on one server and 2 nodes on another. The first server holds the master and is thus declared first.
```
---
- hosts: master_nodes
roles:
# one master per host
- { role: elasticsearch, es_instance_name: "node1", es_heap_size: "1g", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "elastic02:9300", http.port: 9200, transport.tcp.port: 9300, node.data: false, node.master: true, bootstrap.mlockall: false, discovery.zen.ping.multicast.enabled: false } }
vars:
es_scripts: false
@ -126,7 +125,6 @@ An example of a two server deployment, each with 1 node on one server and 2 node
- hosts: data_nodes
roles:
# two nodes per host
- { role: elasticsearch, es_instance_name: "node1", es_data_dir: "/opt/elasticsearch", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "elastic02:9300", http.port: 9200, transport.tcp.port: 9300, node.data: true, node.master: false, bootstrap.mlockall: false, discovery.zen.ping.multicast.enabled: false } }
- { role: elasticsearch, es_instance_name: "node2", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "elastic02:9300", http.port: 9201, transport.tcp.port: 9301, node.data: true, node.master: false, bootstrap.mlockall: false, discovery.zen.ping.multicast.enabled: false } }
vars:
@ -146,17 +144,17 @@ Make sure your hosts are defined in your ```inventory``` file with the appropria
Then run it:
```
ansible-playbook -i hosts ./your-playbook.yml
```ansible-playbook -i hosts ./your-playbook.yml
```
## Configuration
You can add the role without any customisation and it will by default install Java and Elasticsearch, without any plugins.
### Additional Configuration
Additional parameters to es_config allow the customization of the Java and Elasticsearch versions, in addition to role behaviour. Options include:
Following variables affect the versions installed:
* ```es_major_version``` (e.g. "1.5" )
* ```es_version``` (e.g. "1.5.2")
* ```es_major_version``` (e.g. "1.5" ). Should be consistent with es_version.
* ```es_version``` (e.g. "1.5.2"). For versions > 2.x this must be "2.x".
* ```es_start_service``` (true (default) or false)
* ```es_plugins_reinstall``` (true or false (default) )
* ```es_plugins``` (an array of plugin definitons e.g.:
@ -166,9 +164,25 @@ Following variables affect the versions installed:
- plugin: elasticsearch-cloud-aws
version: 2.5.0
```
Earlier examples illustrate the installation of plugins for 2.x. The correct use of this parameter varies depending on the version of Elasticsearch being installed:
- 2.x. - For officially supported plugins no version or source delimiter is required. The plugin script will determine the appropriate plugin version based on the target Elasticsearch version.
For community based plugins include the full path e.g. "lmenezes/elasticsearch-kopf" and the appropriate version for the target version of Elasticsearch.
- 1.x - Full path and version is required for both community and official plugins e.g. "elasticsearch/marvel"
If installing Marvel or Watcher, ensure the license plugin is also specified. Shield configuration is currently not supported but planned for later versions.
* ```java_repos``` (an array of repositories to be added to allow java to be installed)
* ```java_packages``` (an array of packages to be installed to get Java installed)
* ```es_user``` - defaults to elasticsearch.
* ```es_group``` - defaults to elasticsearch.
By default, each node on a host will be installed to use unique pid, plugin, work, data and log directories. These directories are created, using the instance and host name, beneath default locations ]
controlled by the following parameters:
* ```es_pid_dir``` - defaults to "/var/run/elasticsearch".
* ```es_data_dir``` - defaults to "/var/lib/elasticsearch".
* ```es_log_dir``` - defaults to "/var/log/elasticsearch".
* ```es_work_dir``` - defaults to "/tmp/elasticsearch".
* ```es_plugin_dir``` - defaults to "/usr/share/elasticsearch/plugins".
## Notes
@ -176,4 +190,7 @@ Following variables affect the versions installed:
* The playbook relies on the inventory_name of each host to ensure its directories are unique
* Systemd scripts are by default installed in addition to init scripts - with the exception of Debian 8. This is pending improvement and currently relies on the user to determine the preferred mechanism.
* Changing an instance_name for a role application will result in the installation of a new component. The previous component will remain.
* KitchenCI has been used for testing. This is used to confirm images reach the correct state after a play is first applied.
* KitchenCI has been used for testing. This is used to confirm images reach the correct state after a play is first applied. We currently test only the latest version of each major release i.e. 1.7.3 and 2.1.0 on
all supported platforms.
* The role aims to be idempotent. Running the role multiple times, with no changes, should result in no state change on the server. If the configuration is changed, these will be applied and
Elasticsearch restarted where required.

View file

@ -1,6 +1,6 @@
---
es_major_version: "1.7"
es_version: "1.7.3"
es_major_version: "2.x"
es_version: "2.1.0"
es_version_lock: false
es_use_repository: true
es_start_service: true
@ -14,4 +14,5 @@ es_config: {}
es_pid_dir: "/var/run/elasticsearch"
es_data_dir: "/var/lib/elasticsearch"
es_log_dir: "/var/log/elasticsearch"
es_work_dir: "/tmp/elasticsearch"
es_work_dir: "/tmp/elasticsearch"
es_plugin_dir: "/usr/share/elasticsearch/plugins"

View file

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

View file

@ -1,17 +1,17 @@
# Check for mandatory parameters
- fail: msg="es_instance_name must be specified"
when: es_instance_name is not defined
- fail: msg="es_instance_name must be specified and cannot be blank"
when: es_instance_name is not defined or es_instance_name == ''
- 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']}}
- 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'])}}
- fail: msg="Parameter 'http.port' must be defined when multicast is disabled"
- debug: msg="WARNING - It is recommended you specify the parameter 'http.port' when multicast is disabled"
when: not multi_cast and es_config['http.port'] is not defined
- fail: msg="Parameter 'transport.tcp.port' must be defined when multicast is disabled"
- debug: msg="WARNING - It is recommended you specify the parameter 'transport.tcp.port' when multicast is disabled"
when: not multi_cast and es_config['transport.tcp.port'] is not defined
- fail: msg="Parameter 'discovery.zen.ping.unicast.hosts' must be defined when multicast is disabled"
- debug: msg="WARNING - It is recommended you specify the parameter 'discovery.zen.ping.unicast.hosts' when multicast is disabled"
when: not multi_cast and es_config['discovery.zen.ping.unicast.hosts'] is not defined
#If the user attempts to lock memory they must specify a heap size

View file

@ -12,7 +12,7 @@
#For directories we also use the {{inventory_hostname}}-{{ es_instance_name }} - this helps if we have a shared SAN.
- set_fact: pid_dir={{es_pid_dir}}/{{inventory_hostname}}-{{ es_instance_name }}
- set_fact: pid_dir={{ es_pid_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
- set_fact: data_dir={{ es_data_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
@ -34,11 +34,14 @@
file: state=directory path={{ log_dir }} owner={{ es_user }} group={{ es_group }}
- name: Create Config Directory
file: path={{ instance_config_directory }} state=directory owner={{ es_user }} group={{ es_group }}
file: path={{ conf_dir }} state=directory owner={{ es_user }} group={{ es_group }}
- name: Create Plugin Directory
file: state=directory path={{ plugin_dir }} owner={{ es_user }} group={{ es_group }}
#Copy the config template
- name: Copy Configuration File
template: src=elasticsearch.yml.j2 dest={{instance_config_directory}}/elasticsearch.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
template: src=elasticsearch.yml.j2 dest={{conf_dir}}/elasticsearch.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
notify: restart elasticsearch
#Copy the instance specific default file
@ -64,5 +67,7 @@
#Copy the logging.yml
- name: Copy Logging.yml File for Instance
template: src=logging.yml.j2 dest={{instance_config_directory}}/logging.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
notify: restart elasticsearch
template: src=logging.yml.j2 dest={{conf_dir}}/logging.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
notify: restart elasticsearch
#Clean up un-wanted package scripts to avoid confusion

View file

@ -1,15 +1,26 @@
---
- name: Remove elasticsearch plugins
command: /usr/share/elasticsearch/bin/plugin --remove {{ item.plugin }} --silent
command: "{{es_home}}/bin/plugin remove {{ item.plugin }} --silent"
ignore_errors: yes
with_items: es_plugins
when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' ) and es_plugins_reinstall
notify: restart elasticsearch
environment:
CONF_DIR: "{{ conf_dir }}"
- name: Install elasticsearch plugins
#debug: var=item
command: /usr/share/elasticsearch/bin/plugin --install {{ item.plugin }}/{{ item.version }} --silent
register: command_result
failed_when: "'Failed to install' in command_result.stderr"
changed_when: command_result.rc == 0
command: "{{es_home}}/bin/plugin install {{ item.plugin }}{% if item.version is defined and item.version != '' %}/{{ item.version }}{% endif %} --silent"
register: plugin_installed
failed_when: "'Failed to install' in plugin_installed.stderr"
changed_when: plugin_installed.rc == 0
with_items: es_plugins
when: ( ansible_os_family == 'RedHat' or ansible_os_family == 'Debian' )
when: ansible_os_family == 'RedHat' or ansible_os_family == 'Debian'
notify: restart elasticsearch
environment:
CONF_DIR: "{{ conf_dir }}"
#Set permissions on plugins directory
- name: Set Plugin Directory Permissions
file: state=directory path={{ plugin_dir }} owner={{ es_user }} group={{ es_group }} recurse=yes

View file

@ -2,7 +2,8 @@
- set_fact: instance_default_file={{default_file | dirname}}/{{es_instance_name}}_{{default_file | basename}}
- set_fact: instance_init_script={{init_script | dirname }}/{{es_instance_name}}_{{init_script | basename}}
- set_fact: instance_config_directory={{ es_conf_dir }}/{{es_instance_name}}
- set_fact: conf_dir={{ es_conf_dir }}/{{es_instance_name}}
- set_fact: plugin_dir={{ es_plugin_dir }}/{{es_instance_name}}
- set_fact: m_lock_enabled={{ es_config['bootstrap.mlockall'] is defined and es_config['bootstrap.mlockall'] == True }}
- debug: msg="Node configuration {{ es_config }} "
@ -20,7 +21,6 @@
- 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

View file

@ -6,10 +6,7 @@
ES_HOME={{es_home}}
# Elasticsearch configuration directory
CONF_DIR={{instance_config_directory}}
# Elasticsearch configuration file
CONF_FILE={{instance_config_directory}}/elasticsearch.yml
CONF_DIR={{conf_dir}}
# Elasticsearch data directory
DATA_DIR={{data_dir}}

View file

@ -1,5 +1,5 @@
[elasticsearch-{{ es_major_version }}]
name=Elasticsearch repository for {{ es_major_version }}.x packages
name=Elasticsearch repository for {{ es_major_version }} packages
baseurl=http://packages.elastic.co/elasticsearch/{{ es_major_version }}/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch

View file

@ -14,10 +14,12 @@ node.name: {{inventory_hostname}}-{{es_instance_name}}
#################################### Paths ####################################
# Path to directory containing configuration (this file and logging.yml):
path.conf: {{ instance_config_directory }}
path.conf: {{ conf_dir }}
path.data: {{ data_dir }}
path.work: {{ work_dir }}
path.logs: {{ log_dir }}
path.logs: {{ log_dir }}
path.plugins: {{ plugin_dir }}

View file

@ -26,6 +26,7 @@ DESC="Elasticsearch Server - {{es_config['node.name']}}"
{% else %}
DESC="Elasticsearch Server - {{es_instance_name}}"
{% endif %}
DEFAULT=/etc/default/$NAME
if [ `id -u` -ne 0 ]; then
@ -40,23 +41,13 @@ if [ -r /etc/default/rcS ]; then
. /etc/default/rcS
fi
# The following variables can be overwritten in $DEFAULT
# Run Elasticsearch as this user ID and group ID
ES_USER=elasticsearch
ES_GROUP=elasticsearch
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not defined in $DEFAULT)
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"
# Look for the right JVM to use
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
fi
done
export JAVA_HOME
# Directory where the Elasticsearch binary distribution resides
ES_HOME=/usr/share/$NAME
@ -85,15 +76,9 @@ LOG_DIR=/var/log/$NAME
# Elasticsearch data directory
DATA_DIR=/var/lib/$NAME
# Elasticsearch work directory
WORK_DIR=/tmp/$NAME
# Elasticsearch configuration directory
CONF_DIR=/etc/$NAME
# Elasticsearch configuration file (elasticsearch.yml)
CONF_FILE=$CONF_DIR/elasticsearch.yml
# Maximum number of VMA (Virtual Memory Areas) a process can own
MAX_MAP_COUNT=262144
@ -110,15 +95,23 @@ if [ -f "$DEFAULT" ]; then
. "$DEFAULT"
fi
# CONF_FILE setting was removed
if [ ! -z "$CONF_FILE" ]; then
echo "CONF_FILE setting is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed."
exit 1
fi
# Define other required variables
PID_FILE="$PID_DIR/$NAME.pid"
DAEMON=$ES_HOME/bin/elasticsearch
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"
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"
export ES_HEAP_SIZE
export ES_HEAP_NEWSIZE
export ES_DIRECT_SIZE
export ES_JAVA_OPTS
export ES_GC_LOG_FILE
export JAVA_HOME
# Check DAEMON exists
test -x $DAEMON || exit 0
@ -155,15 +148,15 @@ case "$1" in
fi
# Prepare environment
mkdir -p "$LOG_DIR" "$DATA_DIR" "$WORK_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR" "$WORK_DIR"
mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR"
# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
mkdir -p "$PID_DIR" && chown "$ES_USER":"$ES_GROUP" "$PID_DIR"
fi
if [ -n "$PID_FILE" ] && [ ! -e "$PID_FILE" ]; then
touch "$PID_FILE" && chown "$ES_USER":"$ES_GROUP" "$PID_FILE"
fi
# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
mkdir -p "$PID_DIR" && chown "$ES_USER":"$ES_GROUP" "$PID_DIR"
fi
if [ -n "$PID_FILE" ] && [ ! -e "$PID_FILE" ]; then
touch "$PID_FILE" && chown "$ES_USER":"$ES_GROUP" "$PID_FILE"
fi
if [ -n "$MAX_OPEN_FILES" ]; then
ulimit -n $MAX_OPEN_FILES
@ -178,10 +171,9 @@ case "$1" in
fi
# Start Daemon
start-stop-daemon --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
start-stop-daemon -d $ES_HOME --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
return=$?
if [ $return -eq 0 ]
then
if [ $return -eq 0 ]; then
i=0
timeout=10
# Wait for the process to be properly started before exiting
@ -194,17 +186,18 @@ case "$1" in
exit 1
fi
done
else
log_end_msg $return
fi
;;
log_end_msg $return
exit $return
;;
stop)
log_daemon_msg "Stopping $DESC"
if [ -f "$PID_FILE" ]; then
if [ -f "$PID_FILE" ]; then
start-stop-daemon --stop --pidfile "$PID_FILE" \
--user "$ES_USER" \
--retry=TERM/20/KILL/5 >/dev/null
--quiet \
--retry forever/TERM/20 > /dev/null
if [ $? -eq 1 ]; then
log_progress_msg "$DESC is not running but pid file exists, cleaning up"
elif [ $? -eq 3 ]; then
@ -220,7 +213,7 @@ case "$1" in
;;
status)
status_of_proc -p $PID_FILE elasticsearch elasticsearch && exit 0 || exit $?
;;
;;
restart|force-reload)
if [ -f "$PID_FILE" ]; then
$0 stop
@ -234,4 +227,4 @@ case "$1" in
;;
esac
exit 0
exit 0

View file

@ -39,9 +39,8 @@ MAX_OPEN_FILES=65535
MAX_MAP_COUNT=262144
LOG_DIR="/var/log/elasticsearch"
DATA_DIR="/var/lib/elasticsearch"
WORK_DIR="/tmp/elasticsearch"
CONF_DIR="/etc/elasticsearch"
CONF_FILE="/etc/elasticsearch/elasticsearch.yml"
PID_DIR="/var/run/elasticsearch"
# Source the default env file
@ -50,6 +49,12 @@ if [ -f "$ES_ENV_FILE" ]; then
. "$ES_ENV_FILE"
fi
# CONF_FILE setting was removed
if [ ! -z "$CONF_FILE" ]; then
echo "CONF_FILE setting is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed."
exit 1
fi
exec="$ES_HOME/bin/elasticsearch"
prog="elasticsearch"
pidfile="$PID_DIR/${prog}.pid"
@ -58,12 +63,14 @@ export ES_HEAP_SIZE
export ES_HEAP_NEWSIZE
export ES_DIRECT_SIZE
export ES_JAVA_OPTS
export ES_GC_LOG_FILE
export ES_STARTUP_SLEEP_TIME
export JAVA_HOME
lockfile=/var/lock/subsys/$prog
# backwards compatibility for old config sysconfig files, pre 0.90.1
if [ -n $USER ] && [ -z $ES_USER ] ; then
if [ -n $USER ] && [ -z $ES_USER ] ; then
ES_USER=$USER
fi
@ -83,7 +90,6 @@ checkJava() {
start() {
checkJava
[ -x $exec ] || exit 5
[ -f $CONF_FILE ] || exit 6
if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then
echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set"
return 7
@ -97,10 +103,7 @@ start() {
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
fi
if [ -n "$WORK_DIR" ]; then
mkdir -p "$WORK_DIR"
chown "$ES_USER":"$ES_GROUP" "$WORK_DIR"
fi
export ES_GC_LOG_FILE
# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
@ -110,9 +113,10 @@ start() {
touch "$pidfile" && chown "$ES_USER":"$ES_GROUP" "$pidfile"
fi
cd $ES_HOME
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR -Des.default.path.conf=$CONF_DIR
daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
@ -122,7 +126,7 @@ start() {
stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
killproc -p $pidfile -d 20 $prog
killproc -p $pidfile -d 86400 $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile

View file

@ -6,8 +6,7 @@ After=network-online.target
[Service]
Environment=ES_HOME={{es_home}}
Environment=CONF_DIR={{instance_config_directory}}
Environment=CONF_FILE={{instance_config_directory}}/elasticsearch.yml
Environment=CONF_DIR={{conf_dir}}
Environment=DATA_DIR={{data_dir}}
Environment=LOG_DIR={{log_dir}}
Environment=PID_DIR={{pid_dir}}
@ -17,12 +16,13 @@ User={{es_user}}
Group={{es_group}}
ExecStart={{es_home}}/bin/elasticsearch \
-Des.pidfile=$PID_DIR/elasticsearch.pid \
-Des.default.path.home=$ES_HOME \
-Des.default.path.logs=$LOG_DIR \
-Des.default.path.data=$DATA_DIR \
-Des.default.config=$CONF_FILE \
-Des.default.path.conf=$CONF_DIR
-Des.pidfile=${PID_DIR}/elasticsearch.pid \
-Des.default.path.home=${ES_HOME} \
-Des.default.path.logs=${LOG_DIR} \
-Des.default.path.data=${DATA_DIR} \
-Des.default.path.conf=${CONF_DIR}
# Connects standard output to /dev/null
StandardOutput=null
@ -30,9 +30,6 @@ StandardOutput=null
# Connects standard error to journal
StandardError=journal
# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65535
@ -43,8 +40,17 @@ LimitNOFILE=65535
LimitMEMLOCK=infinity
{% endif %}
# Shutdown delay in seconds, before process is tried to be killed with KILL (if configured)
TimeoutStopSec=20
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0
# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM
# Java process is never killed
SendSIGKILL=no
# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,6 @@
require 'config_spec'
describe 'Config Tests v 1.x' do
include_examples 'config::init', "1.7.3"
end

View file

@ -0,0 +1,6 @@
require 'config_spec'
describe 'Config Tests v 2.x' do
include_examples 'config::init', "2.1.0"
end

View file

@ -1,2 +0,0 @@
require 'serverspec'
set :backend, :exec

View file

@ -1,6 +1,6 @@
require 'spec_helper'
context "basic tests" do
shared_examples 'config::init' do |es_version|
describe user('elasticsearch') do
it { should exist }
@ -61,7 +61,7 @@ context "basic tests" do
end
#test we started on the correct port was used
describe command('curl -s "localhost:9201" | grep status') do
describe command('curl -s "localhost:9201"') do
#TODO: This is returning an empty string
#its(:stdout) { should match /\"status\" : 200/ }
its(:exit_status) { should eq 0 }
@ -73,5 +73,20 @@ context "basic tests" do
its(:exit_status) { should eq 0 }
end
describe 'version check' do
it 'should be reported as version '+es_version do
command = command('curl -s localhost:9201 | grep number')
expect(command.stdout).to match(es_version)
expect(command.exit_status).to eq(0)
end
end
#Not copied on Debian 8
#describe file('/usr/lib/systemd/system/node1_elasticsearch.service') do
# it { should be_file }
# it { should contain 'LimitMEMLOCK=infinity' }
#end
end

View file

@ -1,6 +1,6 @@
require 'spec_helper'
context "basic tests" do
shared_examples 'multi::init' do |es_version,plugins|
describe user('elasticsearch') do
it { should exist }
@ -155,6 +155,67 @@ context "basic tests" do
its(:exit_status) { should eq 0 }
end
describe 'version check on master' do
it 'should be reported as version '+es_version do
command = command('curl -s localhost:9200 | grep number')
expect(command.stdout).to match(es_version)
expect(command.exit_status).to eq(0)
end
end
describe 'version check on data' do
it 'should be reported as version '+es_version do
command = command('curl -s localhost:9201 | grep number')
expect(command.stdout).to match(es_version)
expect(command.exit_status).to eq(0)
end
end
#Multi node plugin tests
describe file('/opt/elasticsearch/plugins/node1') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
describe file('/opt/elasticsearch/plugins/master') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
for plugin in plugins
describe file('/opt/elasticsearch/plugins/node1/'+plugin) do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
describe file('/opt/elasticsearch/plugins/master/'+plugin) do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
describe command('curl -s localhost:9200/_nodes/plugins?pretty=true | grep '+plugin) do
its(:exit_status) { should eq 0 }
end
describe command('curl -s localhost:9201/_nodes/plugins?pretty=true | grep '+plugin) do
its(:exit_status) { should eq 0 }
end
end
#Test server spec file has been created and modified - currently not possible as not copied for debian 8
#describe file('/usr/lib/systemd/system/master_elasticsearch.service') do
# it { should be_file }
# it { should contain 'LimitMEMLOCK=infinity' }
#end
#describe file('/usr/lib/systemd/system/node1_elasticsearch.service') do
# it { should be_file }
# it { should_not contain 'LimitMEMLOCK=infinity' }
#end
end

View file

@ -1,6 +1,6 @@
require 'spec_helper'
context "basic tests" do
shared_examples 'package::init' do |es_version,plugins|
describe user('elasticsearch') do
it { should exist }
@ -16,6 +16,10 @@ context "basic tests" do
describe file('/etc/elasticsearch/node1/elasticsearch.yml') do
it { should be_file }
it { should contain 'path.plugins: /usr/share/elasticsearch/plugins/node1' }
it { should contain 'http.port: 9200' }
it { should contain 'transport.tcp.port: 9300' }
it { should contain 'discovery.zen.ping.unicast.hosts: localhost:9300' }
end
describe file('/etc/elasticsearch/node1/scripts') do
@ -23,6 +27,8 @@ context "basic tests" do
it { should be_owned_by 'elasticsearch' }
end
describe file('/etc/elasticsearch/node1/scripts/calculate-score.groovy') do
it { should be_file }
it { should be_owned_by 'elasticsearch' }
@ -52,5 +58,30 @@ context "basic tests" do
end
end
describe 'version check' do
it 'should be reported as version '+es_version do
command = command('curl -s localhost:9200 | grep number')
expect(command.stdout).to match(es_version)
expect(command.exit_status).to eq(0)
end
end
describe file('/usr/share/elasticsearch/plugins/node1') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
for plugin in plugins
describe file('/usr/share/elasticsearch/plugins/node1/'+plugin) do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
describe command('curl -s localhost:9200/_nodes/plugins?pretty=true | grep '+plugin) do
its(:exit_status) { should eq 0 }
end
end
end

View file

@ -8,4 +8,4 @@ RSpec.configure do |config|
config.verbose_retry = true
# show exception that triggers a retry if verbose_retry is set to true
config.display_try_failure_messages = true
end
end

View file

@ -1,6 +1,6 @@
require 'spec_helper'
context "basic tests" do
shared_examples 'standard::init' do |es_version|
describe user('elasticsearch') do
it { should exist }
@ -39,10 +39,10 @@ context "basic tests" do
end
end
describe 'plugin' do
it 'should be reported as existing', :retry => 3, :retry_wait => 10 do
command = command('curl -s localhost:9200/_nodes/?plugin | grep kopf')
expect(command.stdout).to match(/kopf/)
describe 'version check' do
it 'should be reported as version '+es_version do
command = command('curl -s localhost:9200 | grep number')
expect(command.stdout).to match(es_version)
expect(command.exit_status).to eq(0)
end
end

View file

@ -0,0 +1,6 @@
require 'multi_spec'
describe 'Multi Tests v 1.x' do
include_examples 'multi::init', "1.7.3", ["kopf","marvel"]
end

View file

@ -0,0 +1,8 @@
require 'multi_spec'
describe 'Multi Tests v 2.x' do
include_examples 'multi::init', "2.1.0", ["kopf","license","marvel-agent"]
end

View file

@ -7,4 +7,6 @@
- { role: elasticsearch, es_instance_name: "node1", es_config: { "discovery.zen.ping.multicast.enabled": false, discovery.zen.ping.unicast.hosts: "localhost:9300", http.port: 9201, transport.tcp.port: 9301, node.data: true, node.master: false, discovery.zen.ping.multicast.enabled: false } }
vars:
es_scripts: true
es_templates: true
es_templates: true
es_plugin_dir: "/opt/elasticsearch/plugins"
#Plugins installed for this test are specified in .kitchen.yml under suite

View file

@ -1,2 +0,0 @@
require 'serverspec'
set :backend, :exec

View file

@ -0,0 +1,2 @@
---
- host: test-kitchen

View file

@ -0,0 +1,5 @@
require 'package_spec'
describe 'Package Tests v 1.x' do
include_examples 'package::init', "1.7.3", ["kopf","marvel"]
end

View file

@ -0,0 +1,2 @@
---
- host: test-kitchen

View file

@ -0,0 +1,6 @@
require 'package_spec'
describe 'Package Tests v 2.x' do
include_examples 'package::init', "2.1.0", ["kopf","license","marvel-agent"]
end

View file

@ -2,7 +2,8 @@
- name: Elasticsearch Package tests
hosts: localhost
roles:
- { role: elasticsearch, es_config: { "discovery.zen.ping.multicast.enabled": true }, es_instance_name: "node1" }
- { role: elasticsearch, es_config: { "http.port": 9200, "transport.tcp.port":9300, discovery.zen.ping.unicast.hosts: "localhost:9300" }, es_instance_name: "node1" }
vars:
es_scripts: true
es_templates: true
es_templates: true
#Plugins installed for this test are specified in .kitchen.yml under suite

View file

@ -1,2 +0,0 @@
require 'serverspec'
set :backend, :exec

View file

@ -0,0 +1,8 @@
require 'standard_spec'
describe 'Standard Tests v 1.x' do
include_examples 'standard::init', "1.7.3"
end

View file

@ -0,0 +1,2 @@
---
- host: test-kitchen

View file

@ -0,0 +1,9 @@
require 'standard_spec'
describe 'Standard Tests v 2.x' do
include_examples 'standard::init', "2.1.0"
end

View file

@ -0,0 +1,2 @@
---
- host: test-kitchen

View file

@ -4,7 +4,4 @@
roles:
- { role: elasticsearch, es_instance_name: "node1" }
vars:
es_use_repository: "true"
es_plugins:
- plugin: lmenezes/elasticsearch-kopf
version: master
es_use_repository: "true"