server: add "init" event
authorStefan Metzmacher <metze@samba.org>
Tue, 19 Jan 2010 09:07:14 +0000 (10:07 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 20 Jan 2010 08:44:36 +0000 (09:44 +0100)
This is needed because the "startup" event runs after the initial recovery,
but we need to do some actions before the initial recovery.

metze

12 files changed:
common/ctdb_util.c
config/events.d/00.ctdb
config/events.d/01.reclock
config/events.d/10.interface
config/events.d/README
config/notify.sh
include/ctdb.h
include/ctdb_private.h
server/ctdb_daemon.c
server/ctdb_monitor.c
server/eventscript.c
tests/events.d/00.test

index 0b34f2adda427180ec1b640ba92d25c1763147bb..88e8aa8429ae781feed4342634eb9a5a8d2121b3 100644 (file)
@@ -653,6 +653,7 @@ void ctdb_lockdown_memory(struct ctdb_context *ctdb)
 }
 
 const char *ctdb_eventscript_call_names[] = {
+       "init",
        "startup",
        "startrecovery",
        "recovered",
index 9e83d30d239ce12f55e33190e1c9ad6784fdc467..1d4c1459a80661ea7c2c51c7be7b1d9957087228 100755 (executable)
@@ -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
index 919d29697fba52cbcf5e28f06c3a6500119a52d4..345a63150ffe14be4fbecb9c3f13fd7c7d4d9d3c 100755 (executable)
@@ -5,7 +5,7 @@
 loadconfig
 
 case "$1" in 
-    startup)
+    init)
        ctdb_counter_init
        ;;
     
index f881808f1154257680838091962ef9e14e840e7a..5259cba47838f4b43ffe7cabd42ccc7d51b56a97 100755 (executable)
@@ -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 ] && {
index ac7a8f403f89a60feb3c84a799145572c004e315..b783efe4f55a101d4bc0733d22ea0b3ebc1209f1 100644 (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.
index 3a9c86162279254f72f630a2d596bcf08409bb12..890b2fbdf13f393880f76e733deed1af49532817 100755 (executable)
@@ -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
index 3633751ac41ffa791ed7f7ca607fc31e63e8b985..4b2a002b302eb92a89336bb7d96e71eb3aae594a 100644 (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. */
index 653fe0d9ad913ac1ee440d28209b59ef6d88bb58..68c61c9cd283b391d2ddfbfcfd89d582434c30fe 100644 (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
index e96b369ece602a1e2126fff29b5cb93d442c5908..7fbbf3fffb73842a115db7b93e46c5d5fbc30d2e 100644 (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, 
index 729895c68a612117b0a19b8f69b32b3847b97fdf..48a3f32ac8a448b62f3c2d635f3f071227acc4ae 100644 (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;
 
index 9ce9cee484401ff42a3cd3993b079e5f4a2458dd..56e1af50a64af4ac033eb29965e3da1a0f342699 100644 (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;
index fe9926b1a630ae331e8bb38d173952a6a7a04fe7..877e47b6ef15a9115c42f76ed8861422f5ae30cc 100755 (executable)
@@ -16,6 +16,10 @@ case $cmd in
        exit 0; 
        ;;
 
+     init)
+       echo "ctdb init event"
+       exit 0;
+       ;;
      startup)
        echo "ctdb startup event"
        exit 0;