summaryrefslogtreecommitdiffstats
path: root/ctdb/server/eventscript.c
Commit message (Collapse)AuthorAgeFilesLines
...
* server: add "setup" eventStefan Metzmacher2010-02-231-0/+2
| | | | | | | | This is needed because the "init" event can't use 'ctdb' commands. metze (This used to be ctdb commit 1493436b6b24eb05a23b7a339071ad85f70de8f4)
* Ignore any scripts that timesout for most events, except startup.Ronnie Sahlberg2010-02-161-1/+15
| | | | | | Threat hung scripts always (except startup) as success. (This used to be ctdb commit b6d939c9758c7d2e39206838492f2f644dd61db7)
* Reduce loglevel for two eventscript related debug messagesRonnie Sahlberg2010-02-161-2/+2
| | | | (This used to be ctdb commit f8994790e65baebb81bbfad646cdda6234b6d29a)
* server: add updateip eventStefan Metzmacher2010-01-201-0/+3
| | | | | | metze (This used to be ctdb commit 712ed0c4c0bff1be9e96a54b62512787a4aa6259)
* server: add "init" eventStefan Metzmacher2010-01-201-1/+7
| | | | | | | | | This is needed because the "startup" event runs after the initial recovery, but we need to do some actions before the initial recovery. metze (This used to be ctdb commit e953808449c102258abb6cba6f4abf486dda3b82)
* eventscript: fix bug when script is abortedRusty Russell2009-12-181-1/+8
| | | | | | | | | | Another corner case when we terminate running monitor scripts to run something else: logging can flush the output and we write to a NULL pointer. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit eb22c34bccc8a04fcf63efa2bc48d9788709382e)
* eventscript: remove cb_status, fix uninitialized bug when monitoring abortedRusty Russell2009-12-181-36/+61
| | | | | | | | | | | | | | | | | | | | | | (Reapplied with merge after accidental revert) Previously we updated cb_status a each script finished. Since we're storing the status anyway, we can calculate it by iterating the scripts array itself, providing clear and uniform behavior on all code paths. In particular, this fixes a longstanding bug when we abort monitor scripts to run some other script: the cb_status was uninitialized. In this case, we need to hand *something* to the callback; 0 might make us go healthy when we shouldn't. So we use the last status (normally, this will be the just-saved current status). In addition, we make the case of failing the first fork for the script and failing other script forks the same: the error is returned via the callback and saved for viewing through 'ctdb scriptstatus'. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 2c84fe393ff2b961abf77d58a371c24db5ecb93b)
* eventscript: fix cleanup path when setting up script listRusty Russell2009-12-181-4/+5
| | | | | | | | | | | | We shouldn't set ctdb->current_monitor until we set destructor: that's what cleans it up. Also, free state->scripts on no-scripts exit path: it's not a child of state because we need it in the destructor. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 843a2ed5ef85f628788b0caf7417c6b61b5c6d3f)
* version 1.0.109Ronnie Sahlberg2009-12-171-54/+29
| | | | (This used to be ctdb commit 99894a70fe2ebfe43daae7e88ff0fc9cab33e0fb)
* eventscript: remove cb_status, fix uninitialized bug when monitoring abortedRusty Russell2009-12-171-29/+54
| | | | | | | | | | | | | | | | | | | | Previously we updated cb_status a each script finished. Since we're storing the status anyway, we can calculate it by iterating the scripts array itself, providing clear and uniform behavior on all code paths. In particular, this fixes a longstanding bug when we abort monitor scripts to run some other script: the cb_status was uninitialized. In this case, we need to hand *something* to the callback; 0 might make us go healthy when we shouldn't. So we use the last status (normally, this will be the just-saved current status). In addition, we make the case of failing the first fork for the script and failing other script forks the same: the error is returned via the callback and saved for viewing through 'ctdb scriptstatus'. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 5d50f0e16948d18009f6623f132113f7273efc7f)
* Add --valgringing flag instead of --nosetschedRusty Russell2009-12-161-1/+4
| | | | | | | | | | | The do_setsched was being tested for whether to mmap tdbs: let's make it explicit. We can also happily move the kill-child eventscript hack under this flag. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 2ee86cc1f311d7b7504c7b14d142b9c4f6f4b469)
* Author: Rusty Russell <rusty@rustcorp.com.au>Ronnie Sahlberg2009-12-151-0/+3
| | | | | | | | | | | | | | | | | | | | Date: Tue Dec 15 15:53:30 2009 +1030 eventscript: hack to avoid overloading valgrind Now we fork one child per script, when running under valgrind the load gets quite high. This is because valgrind does a lot of work after exit, and we don't wait for the children to finish; we start the next one when the child reports status via the pipe. This fix is ugly, but simple. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 6ed34d5320c39d8a55f2a36ad4c1ab574e0b0796)
* eventscript: fix monitoring when killed by another script commandRusty Russell2009-12-141-7/+14
| | | | | | | | | | | | | | | Commit c1ba1392fe "eventscript: get rid of ctdb_control_event_script_finished altogether" was wrong: there is one case where we want to free the script without transferring their status to last_status. This happens because we always kill an running monitor command when we run any other command. This still isn't quite right (and never was): the callback will be called with status value 0, which might flip us to HEALTHY if we were unhealthy. This is conveniently fixed in my next set of patches :) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 0ea0e27d93398df997d3df9d8bf112358af3a4a5)
* ctdb: scriptstatus can now query non-monitor eventsRusty Russell2009-12-081-8/+11
| | | | | | | | | | | | We also no longer return an error before scripts have been run; a special zero-length data means we have never run the scripts. "ctdb scriptstatus all" returns all event script results. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 9b90d671581e390e2892d3a68f3ca98d58bef4df)
* eventscript: expost call names and enumRusty Russell2009-12-081-24/+15
| | | | | | | | | We're going to need this so ctdb can query non-monitor status. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 53bc5ca23ca55a3ac63a440051f16716944a2a51)
* eventscript: lock logging on timeout.Rusty Russell2009-12-081-1/+2
| | | | | | | | | Ronnie suggested this; seems like a very good idea. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 93153bca68926401dc9ae7fd77ed3f17be923344)
* eventscript: get rid of ctdb_control_event_script_finished altogetherRusty Russell2009-12-081-22/+10
| | | | | | | | | | | | | | | We always have to call it before freeing the state; we should just do this work in the destructor itself. Unfortunately, the script state would already be freed by the time the state destructor is called, so we make the script state a child of ctdb, and talloc_free() it manually on the one path which doesn't use the destructor. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit c1ba1392fe52762960e896ace0aca0ee4faa94d5)
* eventscript: save state for all script invocationsRusty Russell2009-12-081-18/+10
| | | | | | | | | | Rather than only tranferring to last_status for monitor events, do it for every event (ctdb->last_status is now an array). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit c73ea56275d4be76f7ed983d7565b20237dbdce3)
* eventscript: cleanup finished to take state argRusty Russell2009-12-081-15/+10
| | | | | | | | | | | We only need ctdb->current_monitor so we can kill it when we want to run something else; we don't need to use it here as we always know what script we are running. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 4cf1b7c32bcf7e4b65aec1fa7ee1a4b162cac889)
* eventscript: use wire format internally for script status.Rusty Russell2009-12-081-71/+30
| | | | | | | | | | | | | | | | The only difference between the exposed an internal structure now is that the name and output fields were pointers. Switch to using ctdb_scripts_wire/ctdb_script_wire internally as well so marshalling is a noop. We now reject scripts which are too long and truncate logging to the 511 characters we have space for (the entire output will be in the normal ctdbd log). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit fd2f04554e604bc421806be96b987e601473a9b8)
* eventscript: rename ctdb_monitoring_wire to ctdb_scripts_wireRusty Russell2009-12-081-3/+3
| | | | | | | | | | We're going to allow fetching status of all script runs, so this name is no longer appropriate. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit f5cb41ecf3fa986b8af243e8546eb3b985cd902a)
* eventscript: get_current_script() helperRusty Russell2009-12-081-10/+15
| | | | | | | | | | This neatens the code slightly. We also use the name 'current' in ctdb_event_script_handler() for uniformity. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit e9661b383e0c50b9e3d114b7434dfe601aff5744)
* eventscript: use an array rather than a linked list of scriptsRusty Russell2009-12-081-94/+79
| | | | | | | | | | | | | | | | | | | This brings us closer to the wire format, by using a simple array and a 'current' iterator. The downside is that a 'struct ctdb_script' is no longer a talloc object: the state must be passed to our log fn, and the current script extracted with &state->scripts->scripts[state->current]. The wackiness of marshalling is simplified, and as a bonus, we can distinguish between an empty event directory (state->scripts->num_scripts == 0) and and error (state->scripts == NULL). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 76e8bdc11b953398ce8850de57aa51f30cb46bff)
* eventscript: record script status for all eventsRusty Russell2009-12-081-83/+14
| | | | | | | | | | | | | | This unifies almost everything: the state->current pointer points to the struct ctdb_script where we record start, finish, status and output. We still only marshall up the monitor events; the rest disappear when the state structure is freed. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit c476c81f3e3d8fc62f2e53d82fce5774044ee9ce)
* eventscript: use scripts array directly, rather than separate listRusty Russell2009-12-081-50/+48
| | | | | | | | | | | | | | We rename ctdb_monitor_script_status to ctdb_script, and instead of allocating them as the scripts are executed, we allocate them up front and keep a "current" interator. This slightly simplifies the code, though it means we only marshall up to the last successfully run script. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit b2a300768536d10bd867a987ad4cf1c5268c44bc)
* eventscript: ctdb_fork_with_logging()Rusty Russell2009-12-081-22/+15
| | | | | | | | | | | | | | | | | | A new helper functions which sets up an event attached to the child's stdout/stderr which gets routed to the logging callback after being placed in the normal logs. This is a generalization of the previous code which was hardcoded to call ctdb_log_event_script_output. The only subtlety is that we hang the child fds off the output buffer; the destructor for that will flush, which means it has to be destroyed before the output buffer is. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 32cfdc3aec34272612f43a3588e4cabed9c85b68)
* eventscript: remove unused ctbd_ctrl_event_script*Rusty Russell2009-12-081-69/+25
| | | | | | | | | | | | | | The child no longer uses ctdb_ctrl_event_script_init or ctdb_ctrl_event_script_finished, and the others are redundant: it doesn't need to tell us it's starting a script when it only runs one. We move start and stop calls to the parent, and eliminate the RPC infrastructure altogether. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 391926a87a7af73840f10bb314c0a2f951a0854c)
* eventscript: refactor forking code into fork_child_for_script()Rusty Russell2009-12-081-77/+58
| | | | | | | | | | | | | We do the same thing in two places: fire off a child from the initial ctdb_event_script_callback_v() and also from the ctdb_event_script_handler() when it's done. Unify this logic into fork_child_for_script(). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 814704a3286756d40c2a6c508c1c0b77fa711891)
* eventscript: fork() a child for each script.Rusty Russell2009-12-081-59/+105
| | | | | | | | | | | | | | | | | We rename child_run_scripts() to child_run_script(), because it now runs a single script rather than walking the list. When it's finished, we fork the next child from the ctdb_event_script_handler() callback. ctdb_control_event_script_init() and ctdb_control_event_script_finished() are now called directly by the parent process; the child still calls ctdb_ctrl_event_script_start() and ctdb_ctrl_event_script_stop() before and after the script. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 0fafdcb8d3532a05846abaa5805b2e2f3cee8f47)
* eventscript: store from_user and script_list inside state structureRusty Russell2009-12-081-3/+5
| | | | | | | | | | This means all the state about running the scripts is in that structure, which helps in the next patch. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 020fd21e0905e7f11400f6537988645987f2bb32)
* eventscript: use direct script state pointer for current monitorRusty Russell2009-12-081-25/+26
| | | | | | | | | | | | | | | | We put a "scripts" member in ctdb_event_script_state, rather than using a special struct for monitor events. This will fit better as we further unify the different events, and holds the reports from the child process running each monitor script. Rather than making the monitor state a child of current_monitor_status_ctx, we just point current_monitor directly at it. This means we need to reset that pointer in the destructor for ctdb_event_script_state. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 9a2b4f6b17e54685f878d75bad27aa5090b4571f)
* eventscript: make current_monitor_status_ctx serve as monitor_event_script_ctxRusty Russell2009-12-081-36/+14
| | | | | | | | | | | | | | | | We have monitor_event_script_ctx and other_event_script_ctx, and current_monitor_status_ctx in struct ctdb_context. This seems more complex than it needs to be. We use a single "event_script_ctx" as parent for all event script state structures. Then we explicitly reparent monitor events under current_monitor_status_ctx: this is freed every script invocation to kill off any running scripts anyway. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 0d925e6f2767691fa561f15bbb857a2aec531143)
* eventscript: split ctdb_run_event_script into multiple partsRusty Russell2009-12-071-62/+88
| | | | | | | | | | Simple refactoring in preparation for switching to one-child-per-script. We also call the functions run by the child process "child_". Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit bfee777faff75e9bed4aedc1558957483616a6d3)
* eventscript: hoist work out of child process, into parentRusty Russell2009-12-071-22/+24
| | | | | | | | | | | This is the start of a move towards finer-grained reporting, with one child per script. Simple code motion to do sanity check and get the list of scripts before fork(). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 816b9177f51ae5b21b92ff4a404f548fe9723c96)
* eventscript: handle banning within the callbacksRusty Russell2009-12-071-41/+16
| | | | | | | | | | | | | | | | | | | | Currently the timeout handler in eventscript.c does the banning if a timeout happens. However, because monitor events are different, it has to special case them. As we call the callback anyway in this case, we should make that handle -ETIME as it sees fit: for everyone but the monitor event, we simply ban ourselves. The more complicated monitor event banning logic is now in ctdb_monitor.c where it belongs. Note: I wrapped the other bans in "if (status == -ETIME)", though they should probably ban themselves on any error. This change should be a noop. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 9ecee127e19a9e7cae114a66f3514ee7a75276c5)
* eventscript: expost ctdb_ban_self()Rusty Russell2009-12-071-16/+1
| | | | | | | | | eventscript.c uses this now, but our next patch makes others use it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit a305cb7743c24386e464f6b2efab7e2108bb1e7e)
* eventscript: handle v. unlikely timeout raceRusty Russell2009-12-071-0/+1
| | | | | | | | | | If we time out just as the child exits, we currently will report an uninitialized cb_status field. Set it to -ETIME as expected. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 024386931bda9757079f206238ae09bae4de6ea2)
* eventscript: replace other -1 returns with -errnoRusty Russell2009-12-071-22/+20
| | | | | | | | | | | | | | | This completes our "problem with script" reporting; we never set cb_status to -1 on error. Real errnos are used where the failure is a system call (eg. read, setpgid), otherwise -EIO is used if we couldn't communicate with the parent. The latter case is a bit useless, since the parent probably won't see the error anyway, but it's neater. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 1269458547795c90d544371332ba1de68df29548)
* eventscript: simplify ctdb_run_event_script loopRusty Russell2009-12-071-13/+3
| | | | | | | | | | If we break, we avoid cut & paste code inside the loop. Need to initialize ret to 0 for the "no scripts" case. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit ec36ced9446da7e3bf866466d265ee8e18f606c1)
* eventscript: handle and report generic stat/execution errorsRusty Russell2009-12-071-14/+21
| | | | | | | | | | | | | | Rather than ignoring deleted event scripts (or pretending that they were "OK"), and discarding other stat errors, we save the errno and turn it into a negative status. This gives us a bit more information if we can't execute a script (eg. too many symlinks or other weird errors). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 5d894e1ae5228df6bbe4fc305ccba19803fa3798)
* eventscript: use -ENOEXEC for disabled status valueRusty Russell2009-12-071-30/+1
| | | | | | | | | | This unifies code paths and simplifies things: we just hand -ENOEXEC to ctdb_ctrl_event_script_stop(). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit eadf5e44ef97d7703a7d3bce0e7ea0f21cb11f14)
* eventscript: enhance script delete race checkRusty Russell2009-12-071-3/+7
| | | | | | | | | | | | | We currently assume 127 == script removed. The script can also return 127; best to re-check the execution status in this case (and for 126, which will happen if the script is non-executable). If the script is no longer executable/not present, we ignore it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 0a53d6b5ac81daf0efa32f35e7758ede2a5bdb63)
* eventscript: check_executable() to centralize stat/perm checksRusty Russell2009-12-071-11/+32
| | | | | | | | | This is used later in the "script vanished" check. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 8ddb97040842375daf378cbb5816d0c2b031fa65)
* eventscript: use -ETIME for timeout status valueRusty Russell2009-12-071-5/+3
| | | | | | | | | | | | | This starts the move toward more expressive encoding of return values: positive values mean the script ran, negative means we had a problem with the script (and the value is the errno). This does timeout, but changes the ctdb tool to recognize it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 0eb1d0aa14e68b598d9e281c8a02b8f94a042fd9)
* eventscript: marshall onto last_status immediatelyRusty Russell2009-12-071-34/+25
| | | | | | | | | | This simplifies the code a little: last_status is now read to go (it's only used by the scriptstatus command at the moment). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 6be931266a4e41fd0253f760936ad9707dd97c47)
* eventscript: reduce code duplication for ending a script, and fix bugRusty Russell2009-12-021-6/+1
| | | | | | | | | | | | | Commit 50c2caed57c0 removed a gratuitous talloc_steal from the code in ctdb_control_event_script_finished(), but not ctdb_event_script_timeout(). Easiest to call ctdb_control_event_script_finished() at the bottom of the timeout routine. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 17fa252d0d6981fbae8083a818f26d5ce9c5102e)
* Merge commit 'martins/status-test-2'Ronnie Sahlberg2009-12-011-215/+269
|\ | | | | | | | | | | | | | | Conflicts: server/eventscript.c (This used to be ctdb commit e9b3477a5b9a2eff18f727e7d59338bfb5214793)
| * remove a stray ) so we compileRonnie Sahlberg2009-11-271-1/+1
| | | | | | | | (This used to be ctdb commit 16db4882635d84b8410a77e2ea8b08d0a257b0ab)
| * dont use talloc_steal() on a object that is already a child of ctdb.Ronnie Sahlberg2009-11-271-1/+1
| | | | | | | | (This used to be ctdb commit 50c2caed57c0520f506eaaeeb0bba2c272da6ef6)
| * Merge commit 'martins/status-test' into status-test-2Ronnie Sahlberg2009-11-271-0/+1
| |\ | | | | | | | | | (This used to be ctdb commit 937823cc73eb098230acff4b1583f6d01f26c21a)