This can be used from shell-scripts to quickly check the status of the
master node, before launching a series of jobs (and handling the failure
of the jobs due to masterd other issues).
---
man/gnt-cluster.sgml | 21 +++++++++++++++++++++
scripts/gnt-cluster | 21 +++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/man/gnt-cluster.sgml b/man/gnt-cluster.sgml
index da3e547..c58e1ae 100644
--- a/man/gnt-cluster.sgml
+++ b/man/gnt-cluster.sgml
@@ -591,6 +591,27 @@
</refsect2>
<refsect2>
+ <title>MASTER-PING</title>
+
+ <cmdsynopsis>
+ <command>master-ping</command>
+ </cmdsynopsis>
+
+ <para>
+ Checks if the master daemon is alive.
+ </para>
+
+ <para>
+ If the master daemon is alive and can respond to a basic query
+ (the equivalent of <command>gnt-cluster info</command>), then
+ the exit code of the command will be 0. If the master daemon
+ is not alive (either due to a crash or because this is not the
+ master node), the exit code will be 1.
+ </para>
+
+ </refsect2>
+
+ <refsect2>
<title>MODIFY</title>
<cmdsynopsis>
diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster
index 5a2b6c5..930e70a 100755
--- a/scripts/gnt-cluster
+++ b/scripts/gnt-cluster
@@ -517,6 +517,24 @@ def MasterFailover(opts, args):
return bootstrap.MasterFailover(no_voting=opts.no_voting)
+def MasterPing(opts, args):
+ """Checks if the master is alive.
+
+ @param opts: the command line options selected by the user
+ @type args: list
+ @param args: should be an empty list
+ @rtype: int
+ @return: the desired exit code
+
+ """
+ try:
+ cl = GetClient()
+ result = cl.QueryClusterInfo()
+ return 0
+ except:
+ return 1
+
+
def SearchTags(opts, args):
"""Searches the tags on all the cluster.
@@ -857,6 +875,9 @@ commands = {
'master-failover': (
MasterFailover, ARGS_NONE, [NOVOTING_OPT],
"", "Makes the current node the master"),
+ 'master-ping': (
+ MasterPing, ARGS_NONE, [],
+ "", "Checks if the master is alive"),
'version': (
ShowClusterVersion, ARGS_NONE, [],
"", "Shows the cluster version"),
--
1.7.1