From a291d7750b8a12c6999919619e28f8e1bce6a486 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 30 Jul 2003 03:47:55 +0000 Subject: [PATCH] * Eliminated the EXPI command * Completed the configuration item of "purge hour" * Auto-purger now runs as a scheduled job --- citadel/ChangeLog | 6 ++- citadel/control.c | 7 ++++ citadel/routines2.c | 1 + citadel/serv_expire.c | 74 ++++++++++++++++++------------------- citadel/techdoc/session.txt | 20 ++-------- 5 files changed, 51 insertions(+), 57 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 3556973d2..4d99ea5e5 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,9 @@ $Log$ + Revision 608.13 2003/07/30 03:47:53 ajc + * Eliminated the EXPI command + * Completed the configuration item of "purge hour" + * Auto-purger now runs as a scheduled job + Revision 608.12 2003/07/30 00:26:50 ajc * Removed the "weekly" script and began installing a facility to allow database maintenance to happen automatically. (One Step Install can't @@ -4919,4 +4924,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/control.c b/citadel/control.c index 80b72fd8c..52dadbf76 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -196,6 +196,7 @@ void cmd_conf(char *argbuf) cprintf("%ld\n", config.c_net_freq); cprintf("%d\n", config.c_disable_newu); cprintf("%d\n", config.c_aide_mailboxes); + cprintf("%d\n", config.c_purge_hour); cprintf("000\n"); } @@ -330,6 +331,12 @@ void cmd_conf(char *argbuf) if (config.c_aide_mailboxes != 0) config.c_aide_mailboxes = 1; break; + case 31: + if ((config.c_purge_hour >= 0) + && (config.c_purge_hour <= 23)) { + config.c_purge_hour = atoi(buf); + } + break; } ++a; } diff --git a/citadel/routines2.c b/citadel/routines2.c index 374464cbb..b78f4e6af 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -775,6 +775,7 @@ void do_system_configuration(CtdlIPC *ipc) strprompt("Keep messages for how many days?", buf, 10); expirepolicy->expire_value = atol(buf); } + strprompt("Hour to run purges (0-23)", &sc[31][0], 4); /* Save it */ scr_printf("Save this configuration? "); if (yesno()) { diff --git a/citadel/serv_expire.c b/citadel/serv_expire.c index fdf2a01da..a67222173 100644 --- a/citadel/serv_expire.c +++ b/citadel/serv_expire.c @@ -14,8 +14,8 @@ * then the second stage deletes all listed objects from the database. * * At first glance this may seem cumbersome and unnecessary. The reason it is - * implemented in this way is because GDBM (and perhaps some other backends we - * may hook into in the future) explicitly do _not_ support the deletion of + * implemented in this way is because Berkeley DB, and possibly other backends + * we may hook into in the future, explicitly do _not_ support the deletion of * records from a file while the file is being traversed. The delete operation * will succeed, but the traversal is not guaranteed to visit every object if * this is done. Therefore we utilize the two-stage purge. @@ -595,45 +595,41 @@ int PurgeUseTable(void) { } -void cmd_expi(char *argbuf) { - char cmd[SIZ]; +void purge_databases(void) { int retval; + static time_t last_purge = 0; + time_t now; + struct tm tm; - if (CtdlAccessCheck(ac_aide)) return; + /* Do the auto-purge if the current hour equals the purge hour, + * but not if the operation has already been performed in the + * last twelve hours. This is usually enough granularity. + */ + now = time(NULL); + memcpy(&tm, localtime(&now), sizeof(struct tm)); + if (tm.tm_hour != config.c_purge_hour) return; + if ((now - last_purge) < 43200) return; - extract(cmd, argbuf, 0); - if (!strcasecmp(cmd, "users")) { - retval = PurgeUsers(); - cprintf("%d Purged %d users.\n", CIT_OK, retval); - return; - } - else if (!strcasecmp(cmd, "messages")) { - PurgeMessages(); - cprintf("%d Expired %d messages.\n", CIT_OK, messages_purged); - return; - } - else if (!strcasecmp(cmd, "rooms")) { - retval = PurgeRooms(); - cprintf("%d Expired %d rooms.\n", CIT_OK, retval); - return; - } - else if (!strcasecmp(cmd, "visits")) { - retval = PurgeVisits(); - cprintf("%d Purged %d visits.\n", CIT_OK, retval); - } - else if (!strcasecmp(cmd, "usetable")) { - retval = PurgeUseTable(); - cprintf("%d Purged %d entries from the use table.\n", - CIT_OK, retval); - } - else if (!strcasecmp(cmd, "defrag")) { - defrag_databases(); - cprintf("%d Defragmented the databases.\n", CIT_OK); - } - else { - cprintf("%d Invalid command.\n", ERROR+ILLEGAL_VALUE); - return; - } + lprintf(3, "Auto-purger: starting.\n"); + + retval = PurgeUsers(); + lprintf(3, "Purged %d users.\n", retval); + + PurgeMessages(); + lprintf(3, "Expired %d messages.\n", messages_purged); + + retval = PurgeRooms(); + lprintf(3, "Expired %d rooms.\n", retval); + + retval = PurgeVisits(); + lprintf(3, "Purged %d visits.\n", retval); + + retval = PurgeUseTable(); + lprintf(3, "Purged %d entries from the use table.\n", retval); + + lprintf(3, "Auto-purger: finished.\n"); + + last_purge = now; /* So we don't do it again soon */ } /*****************************************************************************/ @@ -726,7 +722,7 @@ void cmd_fsck(char *argbuf) { char *serv_expire_init(void) { - CtdlRegisterProtoHook(cmd_expi, "EXPI", "Expire old system objects"); + CtdlRegisterSessionHook(purge_databases, EVT_TIMER); CtdlRegisterProtoHook(cmd_fsck, "FSCK", "Check message ref counts"); return "$Id$"; } diff --git a/citadel/techdoc/session.txt b/citadel/techdoc/session.txt index d915b685d..f9fcdae24 100644 --- a/citadel/techdoc/session.txt +++ b/citadel/techdoc/session.txt @@ -1755,6 +1755,9 @@ fails for any reason, ERROR is returned. 27. Flag (0 or 1) - allow Aides to zap (forget) rooms 28. Port number for IMAP service 29. How often (in seconds) to run the networker + 30. Flag (0 or 1) - disable self-service new user registration + 31. Flag (0 or 1) - Aides are allowed access to all mailboxes + 32. Hour (0 through 23) during which database auto-purge jobs are run CONF also accepts two additional commands: GETSYS and PUTSYS followed by an arbitrary MIME type (such as application/x-citadel-internet-config) which @@ -1763,23 +1766,6 @@ Configuration room without the need to add extra get/set commands to the server. - EXPI (EXPIre system objects) - - Begins purge operations for objects which, according to site policy, are -"old" and should be removed. EXPI should be called with one argument, one of: - - "messages" (purge old messages out of each room) - "users" (purge old users from the userlog) - "rooms" (remove rooms which have not been posted in for some time) - "visits" (purge dereferenced user/room relationship records) - - EXPI returns OK (probably after a long delay while it does its work) if it -succeeds; otherwise it returns an ERROR code. - - This command is probably temporary, until we can work some sort of scheduler -into the system. It is implemented in the serv_expire module. - - MSG4 (read MeSsaGe, mode 4 -- output in preferred MIME format) -- 2.30.2