1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

Merge commit 'martins-svart/status-test-2' into status-test

(This used to be ctdb commit 143f1fa3cc4588505e3992c601153ea08be8432d)
This commit is contained in:
Martin Schwenke 2009-11-26 16:25:15 +11:00
commit 88cd194d6a
5 changed files with 41 additions and 21 deletions

View File

@ -868,7 +868,8 @@ enum ctdb_eventscript_call {
CTDB_EVENT_STOPPED, /* This node is stopped: no args. */
CTDB_EVENT_MONITOR, /* Please check if service is healthy: no args. */
CTDB_EVENT_STATUS, /* Report service status: no args. */
CTDB_EVENT_SHUTDOWN /* CTDB shutting down: no args. */
CTDB_EVENT_SHUTDOWN, /* CTDB shutting down: no args. */
CTDB_EVENT_RELOAD /* magic */
};
/* internal prototypes */
@ -1345,8 +1346,9 @@ int ctdb_event_script_callback(struct ctdb_context *ctdb,
TALLOC_CTX *mem_ctx,
void (*callback)(struct ctdb_context *, int, void *),
void *private_data,
bool from_user,
enum ctdb_eventscript_call call,
const char *fmt, ...) PRINTF_ATTRIBUTE(6,7);
const char *fmt, ...) PRINTF_ATTRIBUTE(7,8);
void ctdb_release_all_ips(struct ctdb_context *ctdb);
void set_nonblocking(int fd);

View File

@ -224,7 +224,8 @@ static void ctdb_check_health(struct event_context *ev, struct timed_event *te,
if (!ctdb->done_startup) {
ret = ctdb_event_script_callback(ctdb,
ctdb->monitor->monitor_context, ctdb_startup_callback,
ctdb, CTDB_EVENT_STARTUP, "%s", "");
ctdb, false,
CTDB_EVENT_STARTUP, "%s", "");
} else {
int i;
int skip_monitoring = 0;
@ -248,7 +249,8 @@ static void ctdb_check_health(struct event_context *ev, struct timed_event *te,
} else {
ret = ctdb_event_script_callback(ctdb,
ctdb->monitor->monitor_context, ctdb_health_callback,
ctdb, CTDB_EVENT_MONITOR, "%s", "");
ctdb, false,
CTDB_EVENT_MONITOR, "%s", "");
}
}

View File

@ -964,7 +964,9 @@ int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb,
ret = ctdb_event_script_callback(ctdb, state,
ctdb_end_recovery_callback,
state, CTDB_EVENT_RECOVERED, "%s", "");
state,
false,
CTDB_EVENT_RECOVERED, "%s", "");
if (ret != 0) {
ctdb_enable_monitoring(ctdb);
@ -1016,7 +1018,8 @@ int32_t ctdb_control_start_recovery(struct ctdb_context *ctdb,
ret = ctdb_event_script_callback(ctdb, state,
ctdb_start_recovery_callback,
state, CTDB_EVENT_START_RECOVERY,
state, false,
CTDB_EVENT_START_RECOVERY,
"%s", "");
if (ret != 0) {
@ -1229,7 +1232,8 @@ int32_t ctdb_control_stop_node(struct ctdb_context *ctdb, struct ctdb_req_contro
ret = ctdb_event_script_callback(ctdb, state,
ctdb_stop_node_callback,
state, CTDB_EVENT_STOPPED, "%s", "");
state, false,
CTDB_EVENT_STOPPED, "%s", "");
if (ret != 0) {
ctdb_enable_monitoring(ctdb);

View File

@ -236,6 +236,7 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb,
ret = ctdb_event_script_callback(ctdb,
state, takeover_ip_callback, state,
false,
CTDB_EVENT_TAKE_IP,
"%s %s %u",
vnn->iface,
@ -392,6 +393,7 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb,
ret = ctdb_event_script_callback(ctdb,
state, release_ip_callback, state,
false,
CTDB_EVENT_RELEASE_IP,
"%s %s %u",
vnn->iface,
@ -2095,6 +2097,7 @@ int32_t ctdb_control_del_public_address(struct ctdb_context *ctdb, TDB_DATA inda
ret = ctdb_event_script_callback(ctdb,
mem_ctx, delete_ip_callback, mem_ctx,
false,
CTDB_EVENT_RELEASE_IP,
"%s %s %u",
vnn->iface,

View File

@ -42,6 +42,7 @@ static const char *call_names[] = {
"monitor",
"status",
"shutdown",
"reload"
};
static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *p);
@ -461,6 +462,7 @@ static struct ctdb_script_list *ctdb_get_script_list(struct ctdb_context *ctdb,
which allows it to do blocking calls such as system()
*/
static int ctdb_run_event_script(struct ctdb_context *ctdb,
bool from_user,
enum ctdb_eventscript_call call,
const char *options)
{
@ -469,7 +471,7 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
struct ctdb_script_list *scripts, *current;
if (call == CTDB_EVENT_MONITOR) {
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.
@ -521,18 +523,23 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
them
*/
for (current=scripts; current; current=current->next) {
const char *str = from_user ? "CTDB_CALLED_BY_USER=1 " : "";
/* Allow a setting where we run the actual monitor event
from an external source and replace it with
a "status" event that just picks up the actual
status of the event asynchronously.
*/
if ((ctdb->tunable.use_status_events_for_monitoring != 0)
&& call == CTDB_EVENT_MONITOR) {
cmdstr = talloc_asprintf(tmp_ctx, "%s/%s %s",
&& (call == CTDB_EVENT_MONITOR)
&& !from_user) {
cmdstr = talloc_asprintf(tmp_ctx, "%s%s/%s %s",
str,
ctdb->event_script_dir,
current->name, "status");
} else {
cmdstr = talloc_asprintf(tmp_ctx, "%s/%s %s %s",
cmdstr = talloc_asprintf(tmp_ctx, "%s%s/%s %s %s",
str,
ctdb->event_script_dir,
current->name, call_names[call], options);
}
@ -543,7 +550,7 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
child_state.start = timeval_current();
child_state.script_running = cmdstr;
if (call == CTDB_EVENT_MONITOR) {
if (!from_user && call == CTDB_EVENT_MONITOR) {
if (ctdb_ctrl_event_script_start(ctdb, current->name) != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to start event script monitoring\n"));
talloc_free(tmp_ctx);
@ -576,7 +583,7 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
DEBUG(DEBUG_ERR,("Script %s returned status 127. Someone just deleted it?\n", cmdstr));
}
if (call == CTDB_EVENT_MONITOR) {
if (!from_user && call == CTDB_EVENT_MONITOR) {
if (ctdb_ctrl_event_script_stop(ctdb, ret) != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to stop event script monitoring\n"));
talloc_free(tmp_ctx);
@ -587,7 +594,7 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
/* return an error if the script failed */
if (ret != 0) {
DEBUG(DEBUG_ERR,("Event script %s failed with error %d\n", cmdstr, ret));
if (call == CTDB_EVENT_MONITOR) {
if (!from_user && call == CTDB_EVENT_MONITOR) {
if (ctdb_ctrl_event_script_finished(ctdb) != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to finish event script monitoring\n"));
talloc_free(tmp_ctx);
@ -603,7 +610,7 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
child_state.start = timeval_current();
child_state.script_running = "finished";
if (call == CTDB_EVENT_MONITOR) {
if (!from_user && call == CTDB_EVENT_MONITOR) {
if (ctdb_ctrl_event_script_finished(ctdb) != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to finish event script monitoring\n"));
talloc_free(tmp_ctx);
@ -786,6 +793,7 @@ static bool check_options(enum ctdb_eventscript_call call, const char *options)
static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
void (*callback)(struct ctdb_context *, int, void *),
void *private_data,
bool from_user,
enum ctdb_eventscript_call call,
const char *fmt, va_list ap)
{
@ -793,7 +801,7 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
struct ctdb_event_script_state *state;
int ret;
if (call == CTDB_EVENT_MONITOR || call == CTDB_EVENT_STATUS) {
if (!from_user && (call == CTDB_EVENT_MONITOR || call == CTDB_EVENT_STATUS)) {
/* if this was a "monitor" or a status event, we recycle the
context to start a new monitor event
*/
@ -882,7 +890,7 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
close(state->fd[0]);
set_close_on_exec(state->fd[1]);
rt = ctdb_run_event_script(ctdb, state->call, state->options);
rt = ctdb_run_event_script(ctdb, from_user, state->call, state->options);
/* We must be able to write PIPEBUF bytes at least; if this
somehow fails, the read above will be short. */
write(state->fd[1], &rt, sizeof(rt));
@ -918,6 +926,7 @@ int ctdb_event_script_callback(struct ctdb_context *ctdb,
TALLOC_CTX *mem_ctx,
void (*callback)(struct ctdb_context *, int, void *),
void *private_data,
bool from_user,
enum ctdb_eventscript_call call,
const char *fmt, ...)
{
@ -925,7 +934,7 @@ int ctdb_event_script_callback(struct ctdb_context *ctdb,
int ret;
va_start(ap, fmt);
ret = ctdb_event_script_callback_v(ctdb, callback, private_data, call, fmt, ap);
ret = ctdb_event_script_callback_v(ctdb, callback, private_data, from_user, call, fmt, ap);
va_end(ap);
return ret;
@ -960,7 +969,7 @@ int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call
va_start(ap, fmt);
ret = ctdb_event_script_callback_v(ctdb,
event_script_callback, &status, call, fmt, ap);
event_script_callback, &status, false, call, fmt, ap);
if (ret != 0) {
return ret;
}
@ -1074,9 +1083,9 @@ int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb,
ctdb_disable_monitoring(ctdb);
ret = ctdb_event_script_callback(ctdb,
ret = ctdb_event_script_callback(ctdb,
state, run_eventscripts_callback, state,
call, "%s", options);
true, call, "%s", options);
if (ret != 0) {
ctdb_enable_monitoring(ctdb);