EBernhardson has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/341353 )
Change subject: Use a bash script to handle elasticsearch plugin install/removal
......................................................................
Use a bash script to handle elasticsearch plugin install/removal
Versioning of elasticsearch plugins is a complete pain. Whenever there
is an upgrade, either minor or major, it ends up causing problems with
vagrant provisioning all the correct pieces.
The difficulty with the previous solution, a Facter that provides the
elasticsearch version, is that it detects the version *before* the
puppet catalog has been applied. This means a resource that puts the
wikimedia repo into place is not taken into account, and the wrong
version of elasticsearch + plugins can be installed.
This tries to move that complication into a custom bash script, rather
than managing it from puppet. That allows the elasticsearch plugin to
be set to the 'latest' version, and the plugin script to handle making
sure the installed version of elasticsearch matches the installed
version of the plugins.
Change-Id: Ieef00679281884a411569828867a2e1b5939a1c8
---
A puppet/modules/elasticsearch/files/mwv-elasticsearch-plugin
D puppet/modules/elasticsearch/lib/facter/elasticsearch_version.rb
M puppet/modules/elasticsearch/manifests/init.pp
M puppet/modules/elasticsearch/manifests/plugin.pp
4 files changed, 106 insertions(+), 72 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant
refs/changes/53/341353/1
diff --git a/puppet/modules/elasticsearch/files/mwv-elasticsearch-plugin
b/puppet/modules/elasticsearch/files/mwv-elasticsearch-plugin
new file mode 100644
index 0000000..bc43122
--- /dev/null
+++ b/puppet/modules/elasticsearch/files/mwv-elasticsearch-plugin
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+set -e
+
+ES_VERSION=$(dpkg -l elasticsearch 2>/dev/null | awk '$2 == "elasticsearch" {
print $3 }')
+if [ -z "$ES_VERSION" ]; then
+ echo "Elasticsearch not installed"
+ exit 1
+fi
+
+ACTION="$1"
+PLUGIN_NAME="$2"
+if [ -z "$3" ]; then
+ INSTALL_ARGS="$PLUGIN_NAME"
+else
+ # In elasticsearch 2 this is group/title, which elasticsearch will use
+ # to magic up some urls. in elasticsearch 5 we will have to provide our
+ # own urls
+ INSTALL_ARGS="$3/$ES_VERSION"
+fi
+
+PLUGIN_DIR="/usr/share/elasticsearch/plugins/${PLUGIN_NAME}"
+if [ -d "$PLUGIN_DIR" ]; then
+ PLUGIN_INSTALLED="yes"
+ PLUGIN_VERSION=$(awk -F '=' '$1 == "elasticsearch.version" { print $2 }' <
"$PLUGIN_DIR/plugin-descriptor.properties")
+else
+ PLUGIN_INSTALLED="no"
+ PLUGIN_VERSION=""
+fi
+
+
+case "$ACTION" in
+ check)
+ # Check if install is required, used as the 'unless' case in puppet exec
+ if [ "$PLUGIN_INSTALLED" = "yes" -a "$ES_VERSION" = "$PLUGIN_VERSION" ];
then
+ exit 0
+ else
+ exit 1
+ fi
+ ;;
+
+ install)
+ if [ "$PLUGIN_INSTALLED" = "yes" -a "$ES_VERSION" = "$PLUGIN_VERSION" ];
then
+ echo "$PLUGIN_NAME already installed with version $PLUGIN_VERSION"
+ else
+ if [ "$PLUGIN_INSTALLED" = "yes" ]; then
+ echo "Pruning old version ($PLUGIN_VERSION) of $PLUGIN_NAME"
+ /usr/share/elasticsearch/bin/plugin remove "$PLUGIN_NAME"
+ fi
+
+ # We need to delete all old plugins before trying to install a new
+ # one, "bin/plugin install" will simply fail if an unsupported one
+ # is found in the plugins directory.
+ find /usr/share/elasticsearch/plugins -mindepth 1 -maxdepth 1 -type d \
+ '!' '(' -exec test -e '{}/plugin-descriptor.properties' ';' -a \
+ -exec egrep -q
"(^elasticsearch.version=${ES_VERSION}|^site=true)" \
+ '{}/plugin-descriptor.properties' ';' \
+ ')' \
+ -exec sh -c '/usr/share/elasticsearch/bin/plugin remove `basename {}`'
';'
+
+ /usr/share/elasticsearch/bin/plugin install "$INSTALL_ARGS"
+ fi
+ ;;
+
+ uninstall)
+ if [ "$PLUGIN_INSTALLED" = "yes" ]; then
+ /usr/share/elasticsearch/bin/plugin remove "$PLUGIN_NAME"
+ else
+ echo "$PLUGIN_NAME not installed, doing nothing"
+ fi
+ ;;
+
+ *)
+ echo "Unknown action provided. Use [check|install|uninstall]"
+ exit 1
+ ;;
+
+esac
+
diff --git a/puppet/modules/elasticsearch/lib/facter/elasticsearch_version.rb
b/puppet/modules/elasticsearch/lib/facter/elasticsearch_version.rb
deleted file mode 100644
index 7f7a36f..0000000
--- a/puppet/modules/elasticsearch/lib/facter/elasticsearch_version.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# A Facter plugin that returns the Elasticsearch version the next apt run will
upgrade to.
-
-require 'facter'
-
-Facter.add(:elasticsearch_version) do
- setcode do
- policy = Facter::Util::Resolution.exec('apt-cache policy elasticsearch')
- m = /^ *Candidate: (\S+)$/.match(policy)
- m && m[1]
- end
-end
diff --git a/puppet/modules/elasticsearch/manifests/init.pp
b/puppet/modules/elasticsearch/manifests/init.pp
index dd9da85..6d95cf2 100644
--- a/puppet/modules/elasticsearch/manifests/init.pp
+++ b/puppet/modules/elasticsearch/manifests/init.pp
@@ -5,11 +5,18 @@
#
class elasticsearch {
package { 'elasticsearch':
- ensure => $::elasticsearch_version
+ ensure => latest,
}
require_package('openjdk-7-jre-headless')
+ file { '/usr/local/bin/mwv-elasticsearch-plugin':
+ source => 'puppet:///modules/elasticsearch/mwv-elasticsearch-plugin',
+ owner => 'root',
+ group => 'root',
+ mode => '0555',
+ }
+
file { '/var/run/elasticsearch/':
# Temporary and poor work around for
# https://github.com/elastic/elasticsearch/issues/11594
diff --git a/puppet/modules/elasticsearch/manifests/plugin.pp
b/puppet/modules/elasticsearch/manifests/plugin.pp
index 4ff9bb3..888eb54 100644
--- a/puppet/modules/elasticsearch/manifests/plugin.pp
+++ b/puppet/modules/elasticsearch/manifests/plugin.pp
@@ -7,12 +7,11 @@
# [*title*]
# Name of the plugin (artifact). Examples:
# experimental-highlighter-elasticsearch-plugin
-# elasticsearch-analysis-icu
+# analysis-icu
#
# [*group*]
# Group of the plugin. Examples:
# org.wikimedia.search.highlighter
-# elasticsearch
#
# [*esname*]
# Name of the plugin seen by elasticsearch
@@ -27,9 +26,9 @@
# elasticsearch::plugin { 'analysis-icu':
# core => true,
# }
-# Or a specific version of the highlighter plugin:
+#
+# Or the highlighter plugin:
# elasticsearch::plugin { 'experimental-highlighter-elasticsearch-plugin':
-# ensure => '2.3.3.1',
# group => 'org.wikimedia.search.highlighter',
# esname => 'experimental-highlighter',
# }
@@ -37,78 +36,38 @@
define elasticsearch::plugin(
$ensure = present,
$group = undef,
- $esname = undef,
- $url = undef,
+ $esname = $title,
$core = false,
) {
- $es_dir = '/usr/share/elasticsearch'
- $dirname = $esname ? {
- undef => regsubst($title, '^elasticsearch-', ''),
- default => $esname
- }
-
- # FIXME: this might not work well if elastic version is set to 'latest'
- $version = $ensure ? {
- present => $::elasticsearch_version,
- absent => $::elasticsearch_version,
- undef => $::elasticsearch_version,
- default => $ensure
- }
-
- $_esversion = $::elasticsearch_version
-
- $plugin_dir = "${es_dir}/plugins/${dirname}"
- # Core plugins are part of elastic realease process thus no version nor
- # group should be provided.
+ # Core plugins are part of elastic realease process thus no additional
+ # information should be provided. External plugins (such as those released
+ # by wikimedia) provide the group and artifact ids. the
mwv-elasticsearch-plugin
+ # script will add the appropriate version.
$plugin_identifier = $core ? {
- true => $title,
- false => "${group}/${title}/${version}"
+ true => '',
+ false => "${group}/${title}"
}
- $url_param = $url ? {
- undef => '',
- default => "--url ${url}"
- }
case $ensure {
present: {
- exec { "prune_es_plugin_${title}":
- command => "${es_dir}/bin/plugin remove ${dirname}",
- unless => "egrep -s ^version=${version}
${plugin_dir}/plugin-descriptor.properties",
- require => Package['elasticsearch'],
- notify => Service['elasticsearch'],
- }
- # We need to delete all old plugins before trying to install a new
- # one, "bin/plugin install" will simply fail if an unsupported one
is found
- # in the plugins directory
- exec { "cleanup_old_plugins_${title}":
- command => "find ${es_dir}/plugins -mindepth 1 -maxdepth 1
-type d '!' \
- '(' -exec test -e '{}/plugin-descriptor.properties'
';' -a \
- -exec egrep -q
\"(^elasticsearch.version=${_esversion}|^site=true)\" \
- {}/plugin-descriptor.properties \\; ')' \
- -exec sh -c '${es_dir}/bin/plugin remove `basename
{}`' ';'",
- onlyif => "find ${es_dir}/plugins -mindepth 1 -maxdepth 1
-type d '!' \
- '(' -exec test -e '{}/plugin-descriptor.properties'
';' -a \
- -exec egrep -q
\"(^elasticsearch.version=${_esversion}|^site=true)\" \
- {}/plugin-descriptor.properties \\; ')' -print |
grep .",
- require => Package['elasticsearch'],
- notify => Service['elasticsearch'],
- }
exec { "install_es_plugin_${title}":
- command => "${es_dir}/bin/plugin install ${plugin_identifier}
${url_param}",
- unless => "egrep -s ^version=${version}
${plugin_dir}/plugin-descriptor.properties",
+ command => "/usr/local/bin/mwv-elasticsearch-plugin install
${esname} ${plugin_identifier}",
+ unless => "/usr/local/bin/mwv-elasticsearch-plugin check
${esname}",
require => [
Package['elasticsearch'],
- Exec["prune_es_plugin_${title}"],
- Exec["cleanup_old_plugins_${title}"],
+ File['/usr/local/bin/mwv-elasticsearch-plugin']
],
notify => Service['elasticsearch'],
}
}
absent: {
exec { "uninstall_es_plugin_${title}":
- command => "${es_dir}/bin/plugin remove ${title}",
- onlyif => "/usr/bin/test -d ${plugin_dir}",
- require => Package['elasticsearch'],
+ command => "/usr/local/bin/mwv-elasticsearch-plugin remove
${esname}",
+ onlyif => "/usr/bin/test -d
/usr/share/elasticsearch/plugins/${esname}",
+ require => [
+ Package['elasticsearch'],
+ File['/usr/local/bin/mwv-elasticsearch-plugin'],
+ ],
notify => Service['elasticsearch'],
}
}
--
To view, visit https://gerrit.wikimedia.org/r/341353
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieef00679281884a411569828867a2e1b5939a1c8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits