tools/ctdb: "ctdb runstate" now accepts optional expected run state arguments
authorMartin Schwenke <martin@meltin.net>
Fri, 11 Jan 2013 03:09:14 +0000 (14:09 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 24 May 2013 04:08:07 +0000 (14:08 +1000)
If one or more run states are specified then "ctdb runstate" succeeds
only if ctdbd is in one of those run states.

At the moment, if the "setup" event fails then the initscript succeeds
but ctdbd exits almost immediately.  This behaviour isn't very
friendly.

The initscript now waits until ctdbd is in "startup" or "running" run
state via the use of "ctdb runstate startup running", meaning that ctdbd
has successfully passed the "setup" event.

The "setup" event code in 00.ctdb now waits until ctdbd is in the
"setup" run state before proceeding via the use of "ctdb runstate setup".

Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>

config/ctdb.init
config/events.d/00.ctdb
doc/ctdb.1.xml
tools/ctdb.c

index 6c4e16d0de30b21df1cbcc0226649b204673fade..70dcfa642169408d32bf773942764e59ecb8c110 100755 (executable)
@@ -220,7 +220,7 @@ wait_until_ready () {
     _timeout="${1:-10}" # default is 10 seconds
 
     _count=0
-    while ! ctdb ping >/dev/null 2>&1 ; do
+    while ! ctdb runstate startup running >/dev/null 2>&1 ; do
        if [ $_count -ge $_timeout ] ; then
            return 1
        fi
index c1ac11a9236d4219d407bba17fa9bcfc04cbc6d2..02d15691070af2657b0803c0b7c370203afea3f3 100755 (executable)
@@ -53,7 +53,7 @@ wait_until_ready () {
     _timeout="${1:-10}" # default is 10 seconds
 
     _count=0
-    while ! ctdb ping >/dev/null 2>&1 ; do
+    while ! ctdb runstate setup >/dev/null 2>&1 ; do
        if [ $_count -ge $_timeout ] ; then
            return 1
        fi
index d1734b7c8fb578dfcc267b60c0b8ba4a2ddeb338..7242f3aa29afb75c100465aaa3bb574826ff4061 100644 (file)
@@ -382,12 +382,17 @@ response from 3 time=0.000114 sec  (2 clients)
       </screen>
     </refsect2>
 
-    <refsect2><title>runstate</title>
+    <refsect2><title>runstate [setup|startup|running]</title>
       <para>
         Print the runstate of the specified node.  Runstates are used
         to serialise important state transitions in CTDB, particularly
         during startup.
       </para>
+      <para>
+        If one or more optional runstate arguments are specified then
+        the node must be in one of these runstates for the command to
+        succeed.
+      </para>
       <para>
        Example: ctdb runstate
       </para>
index 842c872b6414d48d9c141e2eb7bd6221cc53824d..e21e845073631fb880f9b070b7781f42123626ab 100644 (file)
@@ -4385,6 +4385,29 @@ static int control_runstate(struct ctdb_context *ctdb, int argc, const char **ar
                printf("Unable to get runstate response from node %u\n",
                       options.pnn);
                return -1;
+       } else {
+               bool found = true;
+               enum ctdb_runstate t;
+               int i;
+               for (i=0; i<argc; i++) {
+                       found = false;
+                       t = runstate_from_string(argv[i]);
+                       if (t == CTDB_RUNSTATE_UNKNOWN) {
+                               printf("Invalid run state (%s)\n", argv[i]);
+                               return -1;
+                       }
+
+                       if (t == runstate) {
+                               found = true;
+                               break;
+                       }
+               }
+
+               if (!found) {
+                       printf("CTDB not in required run state (got %s)\n", 
+                              runstate_to_string((enum ctdb_runstate)runstate));
+                       return -1;
+               }
        }
 
        printf("%s\n", runstate_to_string(runstate));
@@ -5824,7 +5847,7 @@ static const struct {
        { "status",          control_status,            true,   false,  "show node status" },
        { "uptime",          control_uptime,            true,   false,  "show node uptime" },
        { "ping",            control_ping,              true,   false,  "ping all nodes" },
-       { "runstate",        control_runstate,          true,   false,  "get runstate of a node" },
+       { "runstate",        control_runstate,          true,   false,  "get/check runstate of a node", "[setup|startup|running]" },
        { "getvar",          control_getvar,            true,   false,  "get a tunable variable",               "<name>"},
        { "setvar",          control_setvar,            true,   false,  "set a tunable variable",               "<name> <value>"},
        { "listvars",        control_listvars,          true,   false,  "list tunable variables"},