return 0;
}
-/*
- tell the main daemon we are starting a new monitor event script
- */
-int ctdb_ctrl_event_script_init(struct ctdb_context *ctdb)
-{
- int ret;
- int32_t res;
-
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_INIT, 0, tdb_null,
- ctdb, NULL, &res, NULL, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,("Failed to send event_script_init\n"));
- return -1;
- }
-
- return 0;
-}
-
-/*
- tell the main daemon we are starting a new monitor event script
- */
-int ctdb_ctrl_event_script_finished(struct ctdb_context *ctdb)
-{
- int ret;
- int32_t res;
-
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_FINISHED, 0, tdb_null,
- ctdb, NULL, &res, NULL, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,("Failed to send event_script_init\n"));
- return -1;
- }
-
- return 0;
-}
-
-/*
- tell the main daemon we are starting to run an eventscript
- */
-int ctdb_ctrl_event_script_start(struct ctdb_context *ctdb, const char *name)
-{
- int ret;
- int32_t res;
- TDB_DATA data;
-
- data.dptr = discard_const(name);
- data.dsize = strlen(name)+1;
-
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_START, 0, data,
- ctdb, NULL, &res, NULL, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,("Failed to send event_script_start\n"));
- return -1;
- }
-
- return 0;
-}
-
-/*
- tell the main daemon the status of the script we ran
- */
-int ctdb_ctrl_event_script_stop(struct ctdb_context *ctdb, int32_t result)
-{
- int ret;
- int32_t res;
- TDB_DATA data;
-
- data.dptr = (uint8_t *)&result;
- data.dsize = sizeof(result);
-
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_STOP, 0, data,
- ctdb, NULL, &res, NULL, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,("Failed to send event_script_stop\n"));
- return -1;
- }
-
- return 0;
-}
-
/*
get the status of running the monitor eventscripts
*/
CTDB_CONTROL_TAKEOVER_IP = 89,
CTDB_CONTROL_GET_PUBLIC_IPS = 90,
CTDB_CONTROL_GET_NODEMAP = 91,
- CTDB_CONTROL_EVENT_SCRIPT_INIT = 92,
- CTDB_CONTROL_EVENT_SCRIPT_START = 93,
- CTDB_CONTROL_EVENT_SCRIPT_STOP = 94,
- CTDB_CONTROL_EVENT_SCRIPT_FINISHED = 95,
CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96,
CTDB_CONTROL_TRAVERSE_KILL = 97,
CTDB_CONTROL_RECD_RECLOCK_LATENCY = 98,
extern int script_log_level;
-int ctdb_ctrl_event_script_init(struct ctdb_context *ctdb);
-int ctdb_ctrl_event_script_start(struct ctdb_context *ctdb, const char *name);
-int ctdb_ctrl_event_script_stop(struct ctdb_context *ctdb, int32_t res);
-int ctdb_ctrl_event_script_finished(struct ctdb_context *ctdb);
-
-int32_t ctdb_control_event_script_init(struct ctdb_context *ctdb);
-int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, TDB_DATA indata);
-int32_t ctdb_control_event_script_stop(struct ctdb_context *ctdb, TDB_DATA indata);
-int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb);
-
-
int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, TDB_DATA *outdata);
int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t len);
CHECK_CONTROL_DATA_SIZE(0);
return ctdb_control_recd_ping(ctdb);
- case CTDB_CONTROL_EVENT_SCRIPT_INIT:
- CHECK_CONTROL_DATA_SIZE(0);
- return ctdb_control_event_script_init(ctdb);
-
- case CTDB_CONTROL_EVENT_SCRIPT_START:
- return ctdb_control_event_script_start(ctdb, indata);
-
- case CTDB_CONTROL_EVENT_SCRIPT_STOP:
- CHECK_CONTROL_DATA_SIZE(sizeof(int32_t));
- return ctdb_control_event_script_stop(ctdb, indata);
-
- case CTDB_CONTROL_EVENT_SCRIPT_FINISHED:
- CHECK_CONTROL_DATA_SIZE(0);
- return ctdb_control_event_script_finished(ctdb);
-
case CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS:
CHECK_CONTROL_DATA_SIZE(0);
return ctdb_control_get_event_script_status(ctdb, outdata);
return 0;
}
-/* called from the event script child process when we are starting a new
- * monitor event
- */
-int32_t ctdb_control_event_script_init(struct ctdb_context *ctdb)
+/* starting a new monitor event */
+static int32_t ctdb_control_event_script_init(struct ctdb_context *ctdb)
{
DEBUG(DEBUG_INFO, ("event script init called\n"));
}
-/* called from the event script child process when we are star running
- * an eventscript
- */
-int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, TDB_DATA indata)
+/* starting a new child to run a monitor event script */
+static int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, const char *name)
{
- const char *name = (const char *)indata.dptr;
struct ctdb_monitor_script_status *script;
DEBUG(DEBUG_INFO, ("event script start called : %s\n", name));
return 0;
}
-/* called from the event script child process when we have finished running
- * an eventscript
- */
-int32_t ctdb_control_event_script_stop(struct ctdb_context *ctdb, TDB_DATA indata)
+/* finished a child running a monitor event script */
+static int32_t ctdb_control_event_script_stop(struct ctdb_context *ctdb, int res)
{
- int32_t res = *((int32_t *)indata.dptr);
struct ctdb_monitor_script_status *script;
if (ctdb->current_monitor == NULL) {
return monitoring_scripts;
}
-/* called from the event script child process when we have completed a
- * monitor event
- */
-int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb)
+/* called when all event script child processes are done */
+static int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb)
{
DEBUG(DEBUG_INFO, ("event script finished called\n"));
return head;
}
-static int child_setup(struct ctdb_context *ctdb,
- bool from_user,
- enum ctdb_eventscript_call call)
+static int child_setup(struct ctdb_context *ctdb)
{
- if (!from_user && call == CTDB_EVENT_MONITOR) {
- /* This is running in the forked child process. At this stage
- * we want to switch from being a ctdb daemon into being a
- * client and connect to the real local daemon.
- */
- if (switch_from_server_to_client(ctdb) != 0) {
- DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch eventscript child into client mode. shutting down.\n"));
- _exit(1);
- }
- }
-
if (setpgid(0,0) != 0) {
int ret = -errno;
DEBUG(DEBUG_ERR,("Failed to create process group for event scripts - %s\n",
}
signal(SIGTERM, sigterm);
-
- child_state.start = timeval_current();
- child_state.script_running = "startup";
return 0;
}
int ret;
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
- ret = child_setup(ctdb, from_user, call);
+ child_state.start = timeval_current();
+ ret = child_setup(ctdb);
if (ret != 0)
goto out;
cmdstr = child_command_string(ctdb, tmp_ctx, from_user,
current->name, call, options);
CTDB_NO_MEMORY(ctdb, cmdstr);
-
- DEBUG(DEBUG_INFO,("Executing event script %s\n",cmdstr));
-
- child_state.start = timeval_current();
child_state.script_running = cmdstr;
- if (!from_user && call == CTDB_EVENT_MONITOR) {
- if (ctdb_ctrl_event_script_start(ctdb, current->name) != 0) {
- ret = -EIO;
- goto out;
- }
-
- if (current->error) {
- if (ctdb_ctrl_event_script_stop(ctdb, -current->error) != 0) {
- ret = -EIO;
- goto out;
- }
- }
- }
+ DEBUG(DEBUG_INFO,("Executing event script %s\n",cmdstr));
if (current->error) {
ret = -current->error;
}
ret = child_run_one(ctdb, current->name, cmdstr);
-
- if (!from_user && call == CTDB_EVENT_MONITOR) {
- if (ctdb_ctrl_event_script_stop(ctdb, ret) != 0) {
- ret = -EIO;
- goto out;
- }
- }
-
- child_state.start = timeval_current();
- child_state.script_running = "finished";
-
out:
talloc_free(tmp_ctx);
return ret;
{
int r;
+ if (!state->from_user && state->call == CTDB_EVENT_MONITOR) {
+ ctdb_control_event_script_start(ctdb, state->script_list->name);
+ }
+
r = pipe(state->fd);
if (r != 0) {
DEBUG(DEBUG_ERR, (__location__ " pipe failed for child eventscript process\n"));
state->cb_status = -errno;
} else if (r != sizeof(state->cb_status)) {
state->cb_status = -EIO;
- } else {
- /* don't stop just because it vanished or was disabled. */
- if (state->cb_status == -ENOENT || state->cb_status == -ENOEXEC) {
- state->cb_status = 0;
- }
+ }
+
+ if (!state->from_user && state->call == CTDB_EVENT_MONITOR) {
+ ctdb_control_event_script_stop(ctdb, state->cb_status);
+ }
+
+ /* don't stop just because it vanished or was disabled. */
+ if (state->cb_status == -ENOENT || state->cb_status == -ENOEXEC) {
+ state->cb_status = 0;
}
state->child = 0;