From 6a52a87028c653edbcede161e96857ff37d802ee Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 19 Jun 2013 10:58:14 +1000 Subject: [PATCH] ctdbd: Refactor shutdown sequence Signed-off-by: Martin Schwenke (This used to be ctdb commit b32fd04bfbf33062d45365b37a7247e272a76ceb) --- ctdb/include/ctdb_private.h | 2 ++ ctdb/server/ctdb_control.c | 13 ++----------- ctdb/server/ctdb_daemon.c | 17 +++++++++++++++++ ctdb/server/ctdb_monitor.c | 11 +---------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index eadd9637155..bf5b5ecacc5 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -450,6 +450,8 @@ const char *runstate_to_string(enum ctdb_runstate runstate); enum ctdb_runstate runstate_from_string(const char *label); void ctdb_set_runstate(struct ctdb_context *ctdb, enum ctdb_runstate runstate); +void ctdb_shutdown_sequence(struct ctdb_context *ctdb, int exit_code); + #define CTDB_MONITORING_ACTIVE 0 #define CTDB_MONITORING_DISABLED 1 diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c index 229ccddb08d..0f2e600b946 100644 --- a/ctdb/server/ctdb_control.c +++ b/ctdb/server/ctdb_control.c @@ -331,17 +331,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, return 0; case CTDB_CONTROL_SHUTDOWN: - DEBUG(DEBUG_NOTICE,("Received SHUTDOWN command. Stopping CTDB daemon.\n")); - ctdb_set_runstate(ctdb, CTDB_RUNSTATE_SHUTDOWN); - ctdb_stop_recoverd(ctdb); - ctdb_stop_keepalive(ctdb); - ctdb_stop_monitoring(ctdb); - ctdb_release_all_ips(ctdb); - ctdb_event_script(ctdb, CTDB_EVENT_SHUTDOWN); - if (ctdb->methods != NULL) { - ctdb->methods->shutdown(ctdb); - } - exit(0); + DEBUG(DEBUG_NOTICE,("Received SHUTDOWN command.\n")); + ctdb_shutdown_sequence(ctdb, 0); case CTDB_CONTROL_TAKEOVER_IPv4: CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ipv4)); diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index b0252556db6..3c813ab9b8c 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -1725,3 +1725,20 @@ int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid) return kill(pid, 0); } + +void ctdb_shutdown_sequence(struct ctdb_context *ctdb, int exit_code) +{ + DEBUG(DEBUG_NOTICE,("Shutdown sequence commencing.\n")); + ctdb_set_runstate(ctdb, CTDB_RUNSTATE_SHUTDOWN); + ctdb_stop_recoverd(ctdb); + ctdb_stop_keepalive(ctdb); + ctdb_stop_monitoring(ctdb); + ctdb_release_all_ips(ctdb); + ctdb_event_script(ctdb, CTDB_EVENT_SHUTDOWN); + if (ctdb->methods != NULL) { + ctdb->methods->shutdown(ctdb); + } + + DEBUG(DEBUG_NOTICE,("Shutdown sequence complete, exiting.\n")); + exit(exit_code); +} diff --git a/ctdb/server/ctdb_monitor.c b/ctdb/server/ctdb_monitor.c index 1608804c308..70ca47d6416 100644 --- a/ctdb/server/ctdb_monitor.c +++ b/ctdb/server/ctdb_monitor.c @@ -294,16 +294,7 @@ static void ctdb_wait_until_recovered(struct event_context *ev, struct timed_eve DEBUG(DEBUG_ALERT,(__location__ "ctdb_recheck_persistent_health() failed (%llu times) - prepare shutdown\n", (unsigned long long)ctdb->db_persistent_check_errors)); - ctdb_stop_recoverd(ctdb); - ctdb_stop_keepalive(ctdb); - ctdb_stop_monitoring(ctdb); - ctdb_release_all_ips(ctdb); - if (ctdb->methods != NULL) { - ctdb->methods->shutdown(ctdb); - } - ctdb_event_script(ctdb, CTDB_EVENT_SHUTDOWN); - DEBUG(DEBUG_ALERT,("ctdb_recheck_persistent_health() failed - Stopping CTDB daemon\n")); - exit(11); + ctdb_shutdown_sequence(ctdb, 11); } ctdb->db_persistent_check_errors = 0;