diff options
author | Amitay Isaacs <amitay@gmail.com> | 2016-11-21 14:52:41 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2016-12-18 14:23:23 +0100 |
commit | a652b5c3515c8cf611f633b95ac894f60e6f4977 (patch) | |
tree | ddd4852bf401bd7b7044d974b926e30d9066c644 /ctdb | |
parent | ca0894e9325e1687a843bc0a79e100a8adc986d4 (diff) | |
download | samba-a652b5c3515c8cf611f633b95ac894f60e6f4977.tar.gz |
ctdb-tool: Add new command "event" to ctdb tool
This command covers all the commands to event daemon.
ctdb event run <event>
ctdb event status [<event>] [lastrun|lastfail|lastpass]
ctdb event script list
ctdb event script enable <script>
ctdb event script disable <script>
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/doc/ctdb.1.xml | 132 | ||||
-rw-r--r-- | ctdb/tools/ctdb.c | 53 |
2 files changed, 185 insertions, 0 deletions
diff --git a/ctdb/doc/ctdb.1.xml b/ctdb/doc/ctdb.1.xml index c2393dcf6ac..db8693630e4 100644 --- a/ctdb/doc/ctdb.1.xml +++ b/ctdb/doc/ctdb.1.xml @@ -615,6 +615,138 @@ Interface[2]: Name:eth5 Link:up References:2 (active) </refsect2> <refsect2> + <title>event run|status|script list|script enable|script disable</title> + <para> + This command is used to control event daemon and to inspect + status of various events. + </para> + + <variablelist> + <varlistentry> + <term>run <parameter>EVENT</parameter> <parameter>TIMEOUT</parameter> <optional><parameter>ARGUMENTS</parameter></optional> </term> + <listitem> + <para> + This command can be used to manually run specified EVENT + with optional ARGUMENTS. The event will be allowed to run + a maximum of TIMEOUT seconds. If TIMEOUT is 0, then there + is no time limit for running the event. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>status <optional><parameter>EVENT</parameter></optional> <optional>lastrun|lastpass|lastfail</optional></term> + <listitem> + <para> + This command displays the last execution status of the + specified EVENT. If no event is specified, then the status + of last executed monitor event will be displayed. + </para> + <para> + To see the last successful execution of the event, lastpass + can be specified. Similarly lastfail can be specified + to see the last unsuccessful execution of the event. + The optional lastrun can be specified to query the last + execution of the event. + </para> + <para> + The command will terminate with the exit status + corresponding to the overall status of event that is + displayed. If lastpass is specified, then the command will + always terminate with 0. If lastfail is specified then the + command will always terminate with non-zero exit status. + If lastrun is specified, then the command will terminate + with 0 or not depending on if the last execution of the + event was successful or not. + </para> + <para> + The output is the list of event scripts executed. + Each line shows the name, status, duration and start time + for each script. + </para> + <para> + Example output: + </para> + <screen> +00.ctdb OK 0.014 Sat Dec 17 19:39:11 2016 +01.reclock OK 0.013 Sat Dec 17 19:39:11 2016 +05.system OK 0.029 Sat Dec 17 19:39:11 2016 +06.nfs OK 0.014 Sat Dec 17 19:39:11 2016 +10.external DISABLED +10.interface OK 0.037 Sat Dec 17 19:39:11 2016 +11.natgw OK 0.011 Sat Dec 17 19:39:11 2016 +11.routing OK 0.007 Sat Dec 17 19:39:11 2016 +13.per_ip_routing OK 0.007 Sat Dec 17 19:39:11 2016 +20.multipathd OK 0.007 Sat Dec 17 19:39:11 2016 +31.clamd OK 0.007 Sat Dec 17 19:39:11 2016 +40.vsftpd OK 0.013 Sat Dec 17 19:39:11 2016 +41.httpd OK 0.018 Sat Dec 17 19:39:11 2016 +49.winbind OK 0.023 Sat Dec 17 19:39:11 2016 +50.samba OK 0.100 Sat Dec 17 19:39:12 2016 +60.nfs OK 0.376 Sat Dec 17 19:39:12 2016 +70.iscsi OK 0.009 Sat Dec 17 19:39:12 2016 +91.lvs OK 0.007 Sat Dec 17 19:39:12 2016 +99.timeout OK 0.007 Sat Dec 17 19:39:12 2016 + </screen> + </listitem> + </varlistentry> + + <varlistentry> + <term>script list</term> + <listitem> + <para> + List the available event scripts. + </para> + <para> + Example output: + </para> + <screen> +00.ctdb +01.reclock +05.system +06.nfs +10.external DISABLED +10.interface +11.natgw +11.routing +13.per_ip_routing +20.multipathd +31.clamd +40.vsftpd +41.httpd +49.winbind +50.samba +60.nfs +70.iscsi +91.lvs +99.timeout + </screen> + </listitem> + </varlistentry> + + <varlistentry> + <term>script enable <parameter>SCRIPT</parameter></term> + <listitem> + <para> + Enable the specified event SCRIPT. Only enabled scripts will be + executed when running any event. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>script disable <parameter>SCRIPT</parameter></term> + <listitem> + <para> + Disable the specified event SCRIPT. This will prevent the script + from executing when running any event. + </para> + </listitem> + </varlistentry> + </variablelist> + </refsect2> + + <refsect2> <title>scriptstatus</title> <para> This command displays which scripts where run in the previous monitoring cycle and the result of each script. If a script failed with an error, causing the node to become unhealthy, the output from that script is also shown. diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 4c03b5c1e95..0fb7d332d8b 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -22,6 +22,7 @@ #include "system/filesys.h" #include "system/time.h" #include "system/wait.h" +#include "system/dir.h" #include <ctype.h> #include <popt.h> @@ -4758,6 +4759,56 @@ static void print_scriptstatus(struct ctdb_script_list **slist, } } +static int control_event(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, + int argc, const char **argv) +{ + char *t, *event_helper = NULL; + char *eventd_socket = NULL; + const char **new_argv; + int i; + + t = getenv("CTDB_EVENT_HELPER"); + if (t != NULL) { + event_helper = talloc_strdup(mem_ctx, t); + } else { + event_helper = talloc_asprintf(mem_ctx, "%s/ctdb_event", + CTDB_HELPER_BINDIR); + } + + if (event_helper == NULL) { + fprintf(stderr, "Unable to set event daemon helper\n"); + return 1; + } + + t = getenv("CTDB_SOCKET"); + if (t != NULL) { + eventd_socket = talloc_asprintf(mem_ctx, "%s/eventd.sock", + dirname(t)); + } else { + eventd_socket = talloc_asprintf(mem_ctx, "%s/eventd.sock", + CTDB_RUNDIR); + } + + if (eventd_socket == NULL) { + fprintf(stderr, "Unable to set event daemon socket\n"); + return 1; + } + + new_argv = talloc_array(mem_ctx, const char *, argc + 1); + if (new_argv == NULL) { + fprintf(stderr, "Memory allocation error\n"); + return 1; + } + + new_argv[0] = eventd_socket; + for (i=0; i<argc; i++) { + new_argv[i+1] = argv[i]; + } + + return run_helper(mem_ctx, "event daemon helper", event_helper, + argc+1, new_argv); +} + static int control_scriptstatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, int argc, const char **argv) { @@ -6307,6 +6358,8 @@ static const struct ctdb_cmd { "wipe the contents of a database.", "<dbname|dbid>"}, { "recmaster", control_recmaster, false, true, "show the pnn for the recovery master", NULL }, + { "event", control_event, true, false, + "event and event script commands", NULL }, { "scriptstatus", control_scriptstatus, false, true, "show event script status", "[init|setup|startup|monitor|takeip|releaseip|ipreallocated]" }, |