summaryrefslogtreecommitdiffstats
path: root/ctdb/server/eventscript.c
diff options
context:
space:
mode:
authorRonnie Sahlberg <sahlberg@samba.org>2008-04-02 11:13:30 +1100
committerRonnie Sahlberg <sahlberg@samba.org>2008-04-02 11:13:30 +1100
commite8e67ef576f3ad2d87590b5bb88ce32e7d8399bb (patch)
treeded8c9aa2c30d291de8bdb56aba14452a480638b /ctdb/server/eventscript.c
parent03d30f405de0ccda5dfed2e9fa702ac19a9b5127 (diff)
downloadsamba-e8e67ef576f3ad2d87590b5bb88ce32e7d8399bb.tar.gz
samba-e8e67ef576f3ad2d87590b5bb88ce32e7d8399bb.tar.xz
samba-e8e67ef576f3ad2d87590b5bb88ce32e7d8399bb.zip
add a mechanism to force a node to run the eventscripts with arbitrary arguments
ctdb eventscript "command argument argument ..." (This used to be ctdb commit 118a16e763d8332c6ce4d8b8e194775fb874c8c8)
Diffstat (limited to 'ctdb/server/eventscript.c')
-rw-r--r--ctdb/server/eventscript.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c
index 705cb4b9a6..f6afd47800 100644
--- a/ctdb/server/eventscript.c
+++ b/ctdb/server/eventscript.c
@@ -367,3 +367,77 @@ int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...)
return status.status;
}
+
+
+struct eventscript_callback_state {
+ struct ctdb_req_control *c;
+};
+
+/*
+ called when takeip event finishes
+ */
+static void run_eventscripts_callback(struct ctdb_context *ctdb, int status,
+ void *private_data)
+{
+ struct eventscript_callback_state *state =
+ talloc_get_type(private_data, struct eventscript_callback_state);
+
+ ctdb_enable_monitoring(ctdb);
+
+ if (status != 0) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to forcibly run eventscripts\n"));
+ ctdb_request_control_reply(ctdb, state->c, NULL, status, NULL);
+ talloc_free(state);
+ return;
+ }
+
+ /* the control succeeded */
+ ctdb_request_control_reply(ctdb, state->c, NULL, 0, NULL);
+ talloc_free(state);
+ return;
+}
+
+/*
+ A control to force running of the eventscripts from the ctdb client tool
+*/
+int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb,
+ struct ctdb_req_control *c,
+ TDB_DATA indata, bool *async_reply)
+{
+ int ret;
+ struct eventscript_callback_state *state;
+
+ /* kill off any previous invokations of forced eventscripts */
+ if (ctdb->eventscripts_ctx) {
+ talloc_free(ctdb->eventscripts_ctx);
+ }
+ ctdb->eventscripts_ctx = talloc_new(ctdb);
+ CTDB_NO_MEMORY(ctdb, ctdb->eventscripts_ctx);
+
+ state = talloc(ctdb->eventscripts_ctx, struct eventscript_callback_state);
+ CTDB_NO_MEMORY(ctdb, state);
+
+ state->c = talloc_steal(ctdb, c);
+
+ DEBUG(DEBUG_NOTICE,("Forced running of eventscripts with arguments %s\n", indata.dptr));
+
+ ctdb_disable_monitoring(ctdb);
+
+ ret = ctdb_event_script_callback(ctdb,
+ timeval_current_ofs(ctdb->tunable.script_timeout, 0),
+ state, run_eventscripts_callback, state,
+ (const char *)indata.dptr);
+
+ if (ret != 0) {
+ ctdb_enable_monitoring(ctdb);
+ DEBUG(DEBUG_ERR,(__location__ " Failed to run eventscripts with arguments %s\n", indata.dptr));
+ talloc_free(state);
+ return -1;
+ }
+
+ /* tell ctdb_control.c that we will be replying asynchronously */
+ *async_reply = true;
+
+ return 0;
+}
+