Filippo Giunchedi has submitted this change and it was merged. Change subject: First of (hopefully many) es-tool commands ......................................................................
First of (hopefully many) es-tool commands `es-tool health` prints out the server's health as a string of "green" "yellow" or "red" Useful because many other scripts want to wait on green. Change-Id: I07c4420c4fe482515f7dd9f175ce2e067c817a1b --- A modules/elasticsearch/files/es-tool M modules/elasticsearch/manifests/init.pp M modules/elasticsearch/manifests/packages.pp 3 files changed, 61 insertions(+), 0 deletions(-) Approvals: Filippo Giunchedi: Verified; Looks good to me, approved Giuseppe Lavagetto: Looks good to me, but someone else must approve diff --git a/modules/elasticsearch/files/es-tool b/modules/elasticsearch/files/es-tool new file mode 100755 index 0000000..5b4ee64 --- /dev/null +++ b/modules/elasticsearch/files/es-tool @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import argparse +import os +import sys + +from elasticsearch import ConnectionError, Elasticsearch + + +# Helper functions go here +def cluster_health(): + es = Elasticsearch(args.server) + return es.cluster.health()["status"] + + +# Add new command functions here +def es_health(): + health = cluster_health() + print health + if health != "green": + return os.EX_UNAVAILABLE + else: + return os.EX_OK + +# And register them here +commands = { + "health": es_health, +} + +# main() +parser = argparse.ArgumentParser( + description="Tool for Elasticsearch cluster maintenance") +parser.add_argument("command", metavar='CMD', type=str, + choices=commands.keys(), + help="Subcommand, one of: " + ",".join(commands)) +parser.add_argument("--server", metavar='S', type=str, default="localhost", + help="Server to work on, default localhost") +args = parser.parse_args() + +try: + sys.exit(commands[args.command]()) +except ConnectionError: + print "Unable to connect" + sys.exit(os.EX_UNAVAILABLE) diff --git a/modules/elasticsearch/manifests/init.pp b/modules/elasticsearch/manifests/init.pp index 963f63e..a4d0903 100644 --- a/modules/elasticsearch/manifests/init.pp +++ b/modules/elasticsearch/manifests/init.pp @@ -152,4 +152,16 @@ file { '/var/log/elasticsearch/elasticsearch_index_search_slowlog.log': ensure => absent } + + # Cluster management tool, trusty only + if ubuntu_version('>= trusty') { + file { '/usr/local/bin/es-tool': + ensure => file, + owner => root, + group => root, + mode => '0755', + source => 'puppet:///modules/elasticsearch/es-tool', + require => Package['python-elasticsearch'] + } + } } diff --git a/modules/elasticsearch/manifests/packages.pp b/modules/elasticsearch/manifests/packages.pp index 2c35efe..db87a1c 100644 --- a/modules/elasticsearch/manifests/packages.pp +++ b/modules/elasticsearch/manifests/packages.pp @@ -17,4 +17,9 @@ if ! defined ( Package['curl'] ) { package { 'curl': ensure => present } } + + # library for elasticsearch. only in trusty+ + if ubuntu_version('>= trusty') { + package { 'python-elasticsearch': ensure => present } + } } -- To view, visit https://gerrit.wikimedia.org/r/163945 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I07c4420c4fe482515f7dd9f175ce2e067c817a1b Gerrit-PatchSet: 9 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Chad <ch...@wikimedia.org> Gerrit-Reviewer: BryanDavis <bda...@wikimedia.org> Gerrit-Reviewer: Chad <ch...@wikimedia.org> Gerrit-Reviewer: Filippo Giunchedi <fgiunch...@wikimedia.org> Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org> Gerrit-Reviewer: Manybubbles <never...@wikimedia.org> Gerrit-Reviewer: Mark Bergsma <m...@wikimedia.org> Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: Ottomata <o...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits