Created
May 15, 2017 14:09
-
-
Save radzhome/a7c2d300c375236e8212a65c151fb63d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def restart_elasticsearch(): | |
""" | |
Restart es from one place using this command | |
Restart one node at a time, starting with master | |
Wait till cluster is in yellow state before doing the next one | |
Usage: | |
fab restart_elasticsearch -H [email protected] | |
""" | |
first_host = env.hosts[0] | |
if '@' in first_host: | |
first_host = first_host[first_host.index('@')+1:] | |
host_prefix = '' | |
if '.' in first_host: | |
host_prefix = first_host[first_host.index('.'):] | |
output = local('curl "{}:9200/_nodes/_all/name"'.format(first_host), capture=True) | |
node_info = json.loads(output).get('nodes') | |
node_names = {v['name']: 1 for k, v in node_info.items()} | |
print("Node names are {}".format(node_names.join(' , '))) | |
del node_names[first_host.replace(host_prefix, '')] | |
second_host = node_names.keys()[0] + host_prefix | |
sudo("service elasticsearch stop") | |
command = 'curl "{}:9200/_cluster/health?wait_for_status=yellow&timeout=150s&pretty"'.format(second_host) | |
output = local(command, capture=True) | |
print(output) | |
sudo("service elasticsearch start") | |
show_info = True | |
if show_info: | |
output = local('curl "{}:9200/_cluster/health?pretty"'.format(second_host), capture=True) | |
health_status = json.loads(output) | |
num_nodes = health_status['number_of_nodes'] | |
cluster_status = health_status['status'] | |
print("Number of nodes: {}".format(num_nodes)) | |
print("Cluster status: {}".format(cluster_status)) | |
print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment