Chad has uploaded a new change for review.
https://gerrit.wikimedia.org/r/164401
Change subject: Another ES node script: restart a node!
......................................................................
Another ES node script: restart a node!
Change-Id: Ic646e2a90e0f71da359fb32e0b1a094eba5340e4
---
M modules/elasticsearch/files/tools/elastictool.py
M modules/elasticsearch/files/tools/es-health
A modules/elasticsearch/files/tools/es-restart-fast
3 files changed, 73 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/puppet
refs/changes/01/164401/1
diff --git a/modules/elasticsearch/files/tools/elastictool.py
b/modules/elasticsearch/files/tools/elastictool.py
index ea5b749..ec1db2f 100644
--- a/modules/elasticsearch/files/tools/elastictool.py
+++ b/modules/elasticsearch/files/tools/elastictool.py
@@ -1,7 +1,9 @@
#!/usr/bin/env python
import argparse
+import sys
from elasticsearch import Elasticsearch
+from elasticsearch import ConnectionError
class ElasticTool:
@@ -14,7 +16,12 @@
def run(self):
self.args = self.parser.parse_args()
self.server = self.args.server
- self.execute()
+ # Catch the most common exception in one place here
+ try:
+ self.execute()
+ except ConnectionError:
+ print "Unable to connect to server: " + self.server
+ sys.exit(1)
def execute(self):
raise NotImplementedError("Please implement this method")
diff --git a/modules/elasticsearch/files/tools/es-health
b/modules/elasticsearch/files/tools/es-health
index e83a9a0..bac9296 100755
--- a/modules/elasticsearch/files/tools/es-health
+++ b/modules/elasticsearch/files/tools/es-health
@@ -3,6 +3,7 @@
import sys
from elastictool import ElasticTool
+
class ServerHealth(ElasticTool):
def execute(self):
health = self.health()
diff --git a/modules/elasticsearch/files/tools/es-restart-fast
b/modules/elasticsearch/files/tools/es-restart-fast
new file mode 100755
index 0000000..f734e29
--- /dev/null
+++ b/modules/elasticsearch/files/tools/es-restart-fast
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import time
+from elastictool import ElasticTool
+from subprocess import Popen
+
+
+class RestartFast(ElasticTool):
+ command = ["/etc/init.d/elasticsearch", "restart"]
+
+ def execute(self):
+ if os.getuid() != 0:
+ print "Must be run as root"
+ sys.exit(1)
+
+ print "Disabling non-primary replication...",
+ if not self.set_replication_state("primaries"):
+ print "failed!"
+ sys.exit(1)
+ print "ok"
+
+ print "Restarting Elasticsearch...",
+ p = Popen(self.command, shell=True)
+ out, err = p.communicate()
+ if p.returncode != 0:
+ print "failed!"
+ sys.exit(1)
+ print "ok"
+
+ print "Waiting for Elasticsearch...",
+ while True:
+ try:
+ if self.health():
+ print "ok"
+ break
+ except:
+ pass
+ print ".",
+ time.sleep(1)
+
+ # Wait a sec
+ time.sleep(1)
+
+ print "Enabling all replication...",
+ if not self.set_replication_state("all"):
+ print "failed! -- You will still need to enable replication " +
+ "again, run `es-start-replication`"
+ sys.exit(1)
+ print "ok"
+
+ # Wait a bit
+ time.sleep(5)
+
+ print "Waiting for green (you can ctrl+c here if you have to)...",
+ while self.health() != "green":
+ time.sleep(1)
+ print "ok"
+
+
+if __name__ == "__main__":
+ tool = RestartFast("Restart Elasticsearch the quick way")
+ tool.run()
--
To view, visit https://gerrit.wikimedia.org/r/164401
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic646e2a90e0f71da359fb32e0b1a094eba5340e4
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Chad <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits