Disable houskeeping and wait for active background jobs to finish before attemtpting...
authorWilfried Goesgens <dothebart@citadel.org>
Tue, 21 Jul 2015 18:57:12 +0000 (20:57 +0200)
committerArt Cancro <ajc@uncensored.citadel.org>
Tue, 21 Jul 2015 21:39:13 +0000 (17:39 -0400)
citadel/housekeeping.c
citadel/include/ctdl_module.h
citadel/modules/migrate/serv_migrate.c

index 11be04e0092133b4cbee41498bce0abfe67cec04..92336277733acaaeaab8a0bd9145dfeea0cf7ee6 100644 (file)
@@ -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<nContexts; i++) 
+               {
+                       if ((nptr[i].state != CON_SYS) || (nptr[i].IO == NULL) || (nptr[i].lastcmd == 0))
+                               continue;
+                       ActiveBackgroundJobs ++;
+                       syslog(LOG_INFO, "Job CC[%d] active; use TERM if you don't want to wait for it",nptr[i].cs_pid);
+               
+               }
+       
+               free(nptr);
+
+       }
+       if (ActiveBackgroundJobs != 0) {
+               syslog(LOG_INFO, "found %d running jobs, need to wait", ActiveBackgroundJobs);
+               usleep(5000000);
+               goto retry_wait_for_contexts;
+       }
+       syslog(LOG_INFO, "Housekeeping disabled now.");
+}
+
+void CtdlEnableHouseKeeping(void)
+{
+       begin_critical_section(S_HOUSEKEEPING);
+       housekeeping_in_progress = 0;
+       end_critical_section(S_HOUSEKEEPING);
+}
index 05a5a7037b80f9f6609222898fe4a7b6a7d6ed0e..ba6a881c88a14a5743f922e277540752663f2128 100644 (file)
@@ -168,6 +168,12 @@ void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg))
 
 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name);
 
+/*
+ * if you say a) (which may take a while)
+ * don't forget to say b)
+ */
+void CtdlDisableHouseKeeping(void);
+void CtdlEnableHouseKeeping(void);
 
 /*
  * Directory services hooks for LDAP etc
index 7dbbdee5f4cc837dbc3261b1eceaa596bc06ef31..3f9ee3a495848d50afb128c51eac1f7b8be7fe12 100644 (file)
@@ -883,6 +883,7 @@ void cmd_migr(char *cmdbuf) {
        
        if (CtdlTrySingleUser())
        {
+               CtdlDisableHouseKeeping();
                CtdlMakeTempFileName(migr_tempfilename1, sizeof migr_tempfilename1);
                CtdlMakeTempFileName(migr_tempfilename2, sizeof migr_tempfilename2);
 
@@ -902,7 +903,8 @@ void cmd_migr(char *cmdbuf) {
 
                unlink(migr_tempfilename1);
                unlink(migr_tempfilename2);
-               
+
+               CtdlEnableHouseKeeping();
                CtdlEndSingleUser();
        }
        else