From 86f2bd9a2d5a4d2eb7640a77e971fdf4ac75cf3c Mon Sep 17 00:00:00 2001 From: Dale McDiarmid Date: Sun, 13 Dec 2015 22:46:50 +0000 Subject: [PATCH] 2.0 Support + Plugin Directory Support + Supporting Tests + Defaults Change --- .kitchen.yml | 52 +++++++++++++-- defaults/main.yml | 7 +- handlers/main.yml | 2 +- tasks/checkParameters.yml | 8 +-- tasks/elasticsearch-config.yml | 11 ++-- tasks/elasticsearch-plugins.yml | 23 +++++-- tasks/elasticsearch.yml | 4 +- templates/elasticsearch.j2 | 5 +- templates/elasticsearch.repo | 2 +- templates/elasticsearch.yml.j2 | 6 +- templates/init/debian/elasticsearch.j2 | 65 +++++++++---------- templates/init/redhat/elasticsearch.j2 | 24 ++++--- templates/systemd/elasticsearch.j2 | 32 +++++---- .../{config => config-1x}/config.yml | 0 .../config-1x/serverspec/default_spec.rb | 6 ++ .../{multi/multi.yml => config-2x/config.yml} | 0 .../config-2x/serverspec/default_spec.rb | 6 ++ .../config/serverspec/spec_helper.rb | 2 - .../{standard => helpers}/serverspec/Gemfile | 0 .../serverspec/config_spec.rb} | 19 +++++- .../serverspec/multi_spec.rb} | 29 ++++++++- .../serverspec/package_spec.rb} | 32 ++++++++- .../serverspec/spec_helper.rb | 2 +- .../serverspec/standard_spec.rb} | 10 +-- .../package.yaml => multi-1x/multi.yml} | 0 .../multi-1x/serverspec/default_spec.rb | 6 ++ .../standard.yml => multi-2x/multi.yml} | 0 .../multi-2x/serverspec/default_spec.rb | 8 +++ .../multi/serverspec/spec_helper.rb | 2 - test/integration/package-1x/package.yaml | 2 + .../package-1x/serverspec/default_spec.rb | 5 ++ test/integration/package-2x/package.yaml | 2 + .../package-2x/serverspec/default_spec.rb | 6 ++ test/integration/package.yml | 4 +- .../package/serverspec/spec_helper.rb | 2 - .../standard-1x/serverspec/default_spec.rb | 8 +++ test/integration/standard-1x/standard.yml | 2 + .../standard-2x/serverspec/default_spec.rb | 9 +++ test/integration/standard-2x/standard.yml | 2 + test/integration/standard.yml | 5 +- 40 files changed, 297 insertions(+), 113 deletions(-) rename test/integration/{config => config-1x}/config.yml (100%) create mode 100644 test/integration/config-1x/serverspec/default_spec.rb rename test/integration/{multi/multi.yml => config-2x/config.yml} (100%) create mode 100644 test/integration/config-2x/serverspec/default_spec.rb delete mode 100644 test/integration/config/serverspec/spec_helper.rb rename test/integration/{standard => helpers}/serverspec/Gemfile (100%) rename test/integration/{config/serverspec/default_spec.rb => helpers/serverspec/config_spec.rb} (81%) rename test/integration/{multi/serverspec/default_spec.rb => helpers/serverspec/multi_spec.rb} (84%) rename test/integration/{package/serverspec/default_spec.rb => helpers/serverspec/package_spec.rb} (61%) rename test/integration/{standard => helpers}/serverspec/spec_helper.rb (98%) rename test/integration/{standard/serverspec/default_spec.rb => helpers/serverspec/standard_spec.rb} (82%) rename test/integration/{package/package.yaml => multi-1x/multi.yml} (100%) create mode 100644 test/integration/multi-1x/serverspec/default_spec.rb rename test/integration/{standard/standard.yml => multi-2x/multi.yml} (100%) create mode 100644 test/integration/multi-2x/serverspec/default_spec.rb delete mode 100644 test/integration/multi/serverspec/spec_helper.rb create mode 100644 test/integration/package-1x/package.yaml create mode 100644 test/integration/package-1x/serverspec/default_spec.rb create mode 100644 test/integration/package-2x/package.yaml create mode 100644 test/integration/package-2x/serverspec/default_spec.rb delete mode 100644 test/integration/package/serverspec/spec_helper.rb create mode 100644 test/integration/standard-1x/serverspec/default_spec.rb create mode 100644 test/integration/standard-1x/standard.yml create mode 100644 test/integration/standard-2x/serverspec/default_spec.rb create mode 100644 test/integration/standard-2x/standard.yml diff --git a/.kitchen.yml b/.kitchen.yml index a1f05b6..5670a29 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -56,24 +56,66 @@ 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: 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 + provisioner: + playbook: test/integration/multi.yml \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml index 86ac56d..22e2c76 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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" \ No newline at end of file +es_work_dir: "/tmp/elasticsearch" +es_plugin_dir: "/usr/share/elasticsearch/plugins" \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml index 3501e12..cec97f9 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 \ No newline at end of file + when: es_start_service and (not elasticsearch_started.changed or plugin_installed.changed) \ No newline at end of file diff --git a/tasks/checkParameters.yml b/tasks/checkParameters.yml index d2a03a4..d2fd2d8 100644 --- a/tasks/checkParameters.yml +++ b/tasks/checkParameters.yml @@ -3,15 +3,15 @@ - fail: msg="es_instance_name must be specified" when: es_instance_name is not defined -- 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 diff --git a/tasks/elasticsearch-config.yml b/tasks/elasticsearch-config.yml index 0a827f2..2295eaf 100644 --- a/tasks/elasticsearch-config.yml +++ b/tasks/elasticsearch-config.yml @@ -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,5 @@ #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 + template: src=logging.yml.j2 dest={{conf_dir}}/logging.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes notify: restart elasticsearch \ No newline at end of file diff --git a/tasks/elasticsearch-plugins.yml b/tasks/elasticsearch-plugins.yml index 15bdf91..b6664df 100644 --- a/tasks/elasticsearch-plugins.yml +++ b/tasks/elasticsearch-plugins.yml @@ -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' ) \ No newline at end of file + 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 \ No newline at end of file diff --git a/tasks/elasticsearch.yml b/tasks/elasticsearch.yml index b921d8b..fce9a04 100644 --- a/tasks/elasticsearch.yml +++ b/tasks/elasticsearch.yml @@ -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 diff --git a/templates/elasticsearch.j2 b/templates/elasticsearch.j2 index 60e4ccf..da71a7b 100644 --- a/templates/elasticsearch.j2 +++ b/templates/elasticsearch.j2 @@ -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}} diff --git a/templates/elasticsearch.repo b/templates/elasticsearch.repo index 810d4c9..9b188e6 100644 --- a/templates/elasticsearch.repo +++ b/templates/elasticsearch.repo @@ -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 diff --git a/templates/elasticsearch.yml.j2 b/templates/elasticsearch.yml.j2 index c31d7da..32db02d 100644 --- a/templates/elasticsearch.yml.j2 +++ b/templates/elasticsearch.yml.j2 @@ -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 }} \ No newline at end of file +path.logs: {{ log_dir }} + +path.plugins: {{ plugin_dir }} \ No newline at end of file diff --git a/templates/init/debian/elasticsearch.j2 b/templates/init/debian/elasticsearch.j2 index b9e65c7..02206cc 100755 --- a/templates/init/debian/elasticsearch.j2 +++ b/templates/init/debian/elasticsearch.j2 @@ -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 \ No newline at end of file diff --git a/templates/init/redhat/elasticsearch.j2 b/templates/init/redhat/elasticsearch.j2 index fab94b3..7925231 100755 --- a/templates/init/redhat/elasticsearch.j2 +++ b/templates/init/redhat/elasticsearch.j2 @@ -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 diff --git a/templates/systemd/elasticsearch.j2 b/templates/systemd/elasticsearch.j2 index bedcceb..35c48a1 100644 --- a/templates/systemd/elasticsearch.j2 +++ b/templates/systemd/elasticsearch.j2 @@ -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 \ No newline at end of file diff --git a/test/integration/config/config.yml b/test/integration/config-1x/config.yml similarity index 100% rename from test/integration/config/config.yml rename to test/integration/config-1x/config.yml diff --git a/test/integration/config-1x/serverspec/default_spec.rb b/test/integration/config-1x/serverspec/default_spec.rb new file mode 100644 index 0000000..404dd30 --- /dev/null +++ b/test/integration/config-1x/serverspec/default_spec.rb @@ -0,0 +1,6 @@ +require 'config_spec' + +describe 'Config Tests v 1.x' do + include_examples 'config::init', "1.7.3" +end + diff --git a/test/integration/multi/multi.yml b/test/integration/config-2x/config.yml similarity index 100% rename from test/integration/multi/multi.yml rename to test/integration/config-2x/config.yml diff --git a/test/integration/config-2x/serverspec/default_spec.rb b/test/integration/config-2x/serverspec/default_spec.rb new file mode 100644 index 0000000..0650ee1 --- /dev/null +++ b/test/integration/config-2x/serverspec/default_spec.rb @@ -0,0 +1,6 @@ +require 'config_spec' + +describe 'Config Tests v 2.x' do + include_examples 'config::init', "2.1.0" +end + diff --git a/test/integration/config/serverspec/spec_helper.rb b/test/integration/config/serverspec/spec_helper.rb deleted file mode 100644 index 590c2fa..0000000 --- a/test/integration/config/serverspec/spec_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'serverspec' -set :backend, :exec diff --git a/test/integration/standard/serverspec/Gemfile b/test/integration/helpers/serverspec/Gemfile similarity index 100% rename from test/integration/standard/serverspec/Gemfile rename to test/integration/helpers/serverspec/Gemfile diff --git a/test/integration/config/serverspec/default_spec.rb b/test/integration/helpers/serverspec/config_spec.rb similarity index 81% rename from test/integration/config/serverspec/default_spec.rb rename to test/integration/helpers/serverspec/config_spec.rb index eb646e4..f8266fb 100644 --- a/test/integration/config/serverspec/default_spec.rb +++ b/test/integration/helpers/serverspec/config_spec.rb @@ -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 diff --git a/test/integration/multi/serverspec/default_spec.rb b/test/integration/helpers/serverspec/multi_spec.rb similarity index 84% rename from test/integration/multi/serverspec/default_spec.rb rename to test/integration/helpers/serverspec/multi_spec.rb index 91e01d1..2ae8695 100644 --- a/test/integration/multi/serverspec/default_spec.rb +++ b/test/integration/helpers/serverspec/multi_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -context "basic tests" do +shared_examples 'multi::init' do |es_version| describe user('elasticsearch') do it { should exist } @@ -155,6 +155,33 @@ 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 + + + #Test server spec file has been created and modified + #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 diff --git a/test/integration/package/serverspec/default_spec.rb b/test/integration/helpers/serverspec/package_spec.rb similarity index 61% rename from test/integration/package/serverspec/default_spec.rb rename to test/integration/helpers/serverspec/package_spec.rb index 29bc14b..ddd0d7a 100644 --- a/test/integration/package/serverspec/default_spec.rb +++ b/test/integration/helpers/serverspec/package_spec.rb @@ -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 } @@ -23,6 +23,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 +54,33 @@ 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 + + #path.plugins: /usr/share/elasticsearch/plugins/node1 + end diff --git a/test/integration/standard/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb similarity index 98% rename from test/integration/standard/serverspec/spec_helper.rb rename to test/integration/helpers/serverspec/spec_helper.rb index 5bef120..1a1bfb5 100644 --- a/test/integration/standard/serverspec/spec_helper.rb +++ b/test/integration/helpers/serverspec/spec_helper.rb @@ -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 \ No newline at end of file diff --git a/test/integration/standard/serverspec/default_spec.rb b/test/integration/helpers/serverspec/standard_spec.rb similarity index 82% rename from test/integration/standard/serverspec/default_spec.rb rename to test/integration/helpers/serverspec/standard_spec.rb index 9e3a51b..07e944d 100644 --- a/test/integration/standard/serverspec/default_spec.rb +++ b/test/integration/helpers/serverspec/standard_spec.rb @@ -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 diff --git a/test/integration/package/package.yaml b/test/integration/multi-1x/multi.yml similarity index 100% rename from test/integration/package/package.yaml rename to test/integration/multi-1x/multi.yml diff --git a/test/integration/multi-1x/serverspec/default_spec.rb b/test/integration/multi-1x/serverspec/default_spec.rb new file mode 100644 index 0000000..d9b1c9c --- /dev/null +++ b/test/integration/multi-1x/serverspec/default_spec.rb @@ -0,0 +1,6 @@ +require 'multi_spec' + + +describe 'Multi Tests v 1.x' do + include_examples 'multi::init', "1.7.3" +end \ No newline at end of file diff --git a/test/integration/standard/standard.yml b/test/integration/multi-2x/multi.yml similarity index 100% rename from test/integration/standard/standard.yml rename to test/integration/multi-2x/multi.yml diff --git a/test/integration/multi-2x/serverspec/default_spec.rb b/test/integration/multi-2x/serverspec/default_spec.rb new file mode 100644 index 0000000..59446dd --- /dev/null +++ b/test/integration/multi-2x/serverspec/default_spec.rb @@ -0,0 +1,8 @@ +require 'multi_spec' + + +describe 'Multi Tests v 2.x' do + include_examples 'multi::init', "2.1.0" +end + + diff --git a/test/integration/multi/serverspec/spec_helper.rb b/test/integration/multi/serverspec/spec_helper.rb deleted file mode 100644 index 590c2fa..0000000 --- a/test/integration/multi/serverspec/spec_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'serverspec' -set :backend, :exec diff --git a/test/integration/package-1x/package.yaml b/test/integration/package-1x/package.yaml new file mode 100644 index 0000000..a3c37e1 --- /dev/null +++ b/test/integration/package-1x/package.yaml @@ -0,0 +1,2 @@ +--- +- host: test-kitchen diff --git a/test/integration/package-1x/serverspec/default_spec.rb b/test/integration/package-1x/serverspec/default_spec.rb new file mode 100644 index 0000000..b22af05 --- /dev/null +++ b/test/integration/package-1x/serverspec/default_spec.rb @@ -0,0 +1,5 @@ +require 'package_spec' + +describe 'Package Tests v 1.x' do + include_examples 'package::init', "1.7.3", ["kopf","marvel"] +end \ No newline at end of file diff --git a/test/integration/package-2x/package.yaml b/test/integration/package-2x/package.yaml new file mode 100644 index 0000000..a3c37e1 --- /dev/null +++ b/test/integration/package-2x/package.yaml @@ -0,0 +1,2 @@ +--- +- host: test-kitchen diff --git a/test/integration/package-2x/serverspec/default_spec.rb b/test/integration/package-2x/serverspec/default_spec.rb new file mode 100644 index 0000000..f87daf7 --- /dev/null +++ b/test/integration/package-2x/serverspec/default_spec.rb @@ -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 \ No newline at end of file diff --git a/test/integration/package.yml b/test/integration/package.yml index 13710e7..79a89db 100644 --- a/test/integration/package.yml +++ b/test/integration/package.yml @@ -2,7 +2,7 @@ - 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 \ No newline at end of file + es_templates: true diff --git a/test/integration/package/serverspec/spec_helper.rb b/test/integration/package/serverspec/spec_helper.rb deleted file mode 100644 index 590c2fa..0000000 --- a/test/integration/package/serverspec/spec_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'serverspec' -set :backend, :exec diff --git a/test/integration/standard-1x/serverspec/default_spec.rb b/test/integration/standard-1x/serverspec/default_spec.rb new file mode 100644 index 0000000..67f3c99 --- /dev/null +++ b/test/integration/standard-1x/serverspec/default_spec.rb @@ -0,0 +1,8 @@ +require 'standard_spec' + + +describe 'Standard Tests v 1.x' do + include_examples 'standard::init', "1.7.3" +end + + diff --git a/test/integration/standard-1x/standard.yml b/test/integration/standard-1x/standard.yml new file mode 100644 index 0000000..a3c37e1 --- /dev/null +++ b/test/integration/standard-1x/standard.yml @@ -0,0 +1,2 @@ +--- +- host: test-kitchen diff --git a/test/integration/standard-2x/serverspec/default_spec.rb b/test/integration/standard-2x/serverspec/default_spec.rb new file mode 100644 index 0000000..3d61cb0 --- /dev/null +++ b/test/integration/standard-2x/serverspec/default_spec.rb @@ -0,0 +1,9 @@ +require 'standard_spec' + + +describe 'Standard Tests v 2.x' do + include_examples 'standard::init', "2.1.0" +end + + + diff --git a/test/integration/standard-2x/standard.yml b/test/integration/standard-2x/standard.yml new file mode 100644 index 0000000..a3c37e1 --- /dev/null +++ b/test/integration/standard-2x/standard.yml @@ -0,0 +1,2 @@ +--- +- host: test-kitchen diff --git a/test/integration/standard.yml b/test/integration/standard.yml index 66fd90e..fc5798f 100644 --- a/test/integration/standard.yml +++ b/test/integration/standard.yml @@ -4,7 +4,4 @@ roles: - { role: elasticsearch, es_instance_name: "node1" } vars: - es_use_repository: "true" - es_plugins: - - plugin: lmenezes/elasticsearch-kopf - version: master \ No newline at end of file + es_use_repository: "true" \ No newline at end of file