1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00

server: add "init" event

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)
This commit is contained in:
Stefan Metzmacher 2010-01-19 10:07:14 +01:00
parent 8456a1b0ef
commit fd06167caa
12 changed files with 44 additions and 10 deletions

View File

@ -653,6 +653,7 @@ void ctdb_lockdown_memory(struct ctdb_context *ctdb)
}
const char *ctdb_eventscript_call_names[] = {
"init",
"startup",
"startrecovery",
"recovered",

View File

@ -13,7 +13,7 @@
loadconfig
case "$1" in
startup)
init)
# make sure we have a blank state directory for the scripts to work with
/bin/rm -rf $CTDB_BASE/state
/bin/mkdir -p $CTDB_BASE/state

View File

@ -5,7 +5,7 @@
loadconfig
case "$1" in
startup)
init)
ctdb_counter_init
;;

View File

@ -20,7 +20,7 @@ loadconfig
case "$1" in
#############################
# called when ctdbd starts up
startup)
init)
# make sure that we only respond to ARP messages from the NIC where
# a particular ip address is associated.
[ -f /proc/sys/net/ipv4/conf/all/arp_filter ] && {

View File

@ -22,11 +22,20 @@ All of the events except the 'shutdown' and 'startrecovery' events will be
called with the ctdb daemon in NORMAL mode (ie. not in recovery)
The events currently implemented are
startup
init
This event does not take any additional arguments.
This event is only invoked once, when ctdb is starting up.
This event is used to wait for the service to start and all
resources for the service becoming available.
This event is used to do some cleanup work from earlier runs
and prepare the basic setup.
Example: 00.ctdb cleans up $CTDB_BASE/state
startup
This event does not take any additional arguments.
This event is only invoked once, when ctdb has finished
the initial recoveries. This event is used to wait for
the service to start and all resources for the service
becoming available.
This is used to prevent ctdb from starting up and advertize its
services until all dependent services have become available.

View File

@ -33,7 +33,12 @@ case $event in
# or do something else ...
;;
startup)
# do some extra magic when ctdb has started?
# do some extra magic when ctdb has finished the initial
# recovery?
;;
init)
# do some extra magic when ctdb has started?
;;
esac

View File

@ -679,7 +679,8 @@ struct ctdb_scripts_wire {
/* different calls to event scripts. */
enum ctdb_eventscript_call {
CTDB_EVENT_STARTUP, /* CTDB starting up: no args. */
CTDB_EVENT_INIT, /* CTDB starting up: no args */
CTDB_EVENT_STARTUP, /* CTDB starting up after initial recovery: no args. */
CTDB_EVENT_START_RECOVERY, /* CTDB recovery starting: no args. */
CTDB_EVENT_RECOVERED, /* CTDB recovery finished: no args. */
CTDB_EVENT_TAKE_IP, /* IP taken: interface, IP address, netmask bits. */

View File

@ -1564,5 +1564,7 @@ int ctdb_update_persistent_health(struct ctdb_context *ctdb,
int num_healthy_nodes);
int ctdb_recheck_persistent_health(struct ctdb_context *ctdb);
void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event);
void ctdb_fault_setup(void);
#endif

View File

@ -781,6 +781,12 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog)
ctdb_fatal(ctdb, "Failed to get initial freeze\n");
}
ret = ctdb_event_script(ctdb, CTDB_EVENT_INIT);
if (ret != 0) {
ctdb_fatal(ctdb, "Failed to run init event\n");
}
ctdb_run_notification_script(ctdb, "init");
/* now start accepting clients, only can do this once frozen */
fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd,
EVENT_FD_READ|EVENT_FD_AUTOCLOSE,

View File

@ -75,7 +75,7 @@ static int ctdb_run_notification_script_child(struct ctdb_context *ctdb, const c
return ret;
}
static void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event)
void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event)
{
pid_t child;

View File

@ -589,6 +589,7 @@ static bool check_options(enum ctdb_eventscript_call call, const char *options)
{
switch (call) {
/* These all take no arguments. */
case CTDB_EVENT_INIT:
case CTDB_EVENT_STARTUP:
case CTDB_EVENT_START_RECOVERY:
case CTDB_EVENT_RECOVERED:
@ -649,7 +650,12 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
/* we guarantee that only some specifically allowed event scripts are run
while in recovery */
const enum ctdb_eventscript_call allowed_calls[] = {
CTDB_EVENT_START_RECOVERY, CTDB_EVENT_SHUTDOWN, CTDB_EVENT_RELEASE_IP, CTDB_EVENT_STOPPED };
CTDB_EVENT_INIT,
CTDB_EVENT_START_RECOVERY,
CTDB_EVENT_SHUTDOWN,
CTDB_EVENT_RELEASE_IP,
CTDB_EVENT_STOPPED
};
int i;
for (i=0;i<ARRAY_SIZE(allowed_calls);i++) {
if (call == allowed_calls[i]) break;

View File

@ -16,6 +16,10 @@ case $cmd in
exit 0;
;;
init)
echo "ctdb init event"
exit 0;
;;
startup)
echo "ctdb startup event"
exit 0;