From cbc736c6fd45401b653454914a1b437050600a00 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Tue, 21 Jul 2015 20:57:12 +0200 Subject: [PATCH] Disable houskeeping and wait for active background jobs to finish before attemtpting migrating. --- citadel/housekeeping.c | 57 ++++++++++++++++++++++++++ citadel/include/ctdl_module.h | 6 +++ citadel/modules/migrate/serv_migrate.c | 4 +- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/citadel/housekeeping.c b/citadel/housekeeping.c index 11be04e00..923362777 100644 --- a/citadel/housekeeping.c +++ b/citadel/housekeeping.c @@ -129,3 +129,60 @@ void do_housekeeping(void) { housekeeping_in_progress = 0; end_critical_section(S_HOUSEKEEPING); } + +void CtdlDisableHouseKeeping(void) +{ + int ActiveBackgroundJobs; + int do_housekeeping_now = 0; + struct CitContext *nptr; + int nContexts, i; + +retry_block_housekeeping: + syslog(LOG_INFO, "trying to disable housekeeping services"); + begin_critical_section(S_HOUSEKEEPING); + if (housekeeping_in_progress == 0) { + do_housekeeping_now = 1; + housekeeping_in_progress = 1; + } + end_critical_section(S_HOUSEKEEPING); + if (do_housekeeping_now == 0) { + usleep(1000000); + goto retry_block_housekeeping; + } + + syslog(LOG_INFO, "checking for running server Jobs"); + +retry_wait_for_contexts: + /* So that we don't keep the context list locked for a long time + * we create a copy of it first + */ + ActiveBackgroundJobs = 0; + nptr = CtdlGetContextArray(&nContexts) ; + if (nptr) + { + for (i=0; i