From de64f48d485d2521b292054d4d4b769f2e9dce25 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Fri, 8 Oct 2010 19:19:59 +0000 Subject: [PATCH] Closes #189 "Cleanup process slows down considerably the Apache server" --- build/lemonldap-ng/Makefile | 4 ++ .../liblemonldap-ng-handler-perl.cron.d | 4 ++ .../liblemonldap-ng-handler-perl.install | 1 + build/lemonldap-ng/debian/rules | 1 + .../Lemonldap/NG/Common/Conf/Serializer.pm | 7 ++-- modules/lemonldap-ng-handler/MANIFEST | 2 + .../example/scripts/purgeLocalCache | 38 +++++++++++++++++++ .../example/scripts/purgeLocalCache.cron.d | 4 ++ .../example/scripts/purgeCentralCache | 3 +- 9 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 build/lemonldap-ng/debian/liblemonldap-ng-handler-perl.cron.d create mode 100755 modules/lemonldap-ng-handler/example/scripts/purgeLocalCache create mode 100644 modules/lemonldap-ng-handler/example/scripts/purgeLocalCache.cron.d diff --git a/build/lemonldap-ng/Makefile b/build/lemonldap-ng/Makefile index b30da7f4c..d404abd12 100644 --- a/build/lemonldap-ng/Makefile +++ b/build/lemonldap-ng/Makefile @@ -219,6 +219,7 @@ install_bin: install_conf_dir # Binary install @install -v -d $(RBINDIR) @cp --preserve=mode --remove-destination \ + ${SRCHANDLERDIR}/example/scripts/purgeLocalCache \ ${SRCPORTALDIR}/example/scripts/purgeCentralCache \ ${SRCPORTALDIR}/example/scripts/buildPortalWSDL \ ${SRCCOMMONDIR}/scripts/convertConfig \ @@ -355,6 +356,7 @@ install_handler_site: install_conf_dir @cp --remove-destination ${SRCHANDLERDIR}/example/MyHandlerZimbra.pm ${RHANDLERDIR} @cp --remove-destination ${SRCHANDLERDIR}/example/MyHandlerSympa.pm ${RHANDLERDIR} @cp --remove-destination ${SRCHANDLERDIR}/example/MyUpdateCookieHandler.pm ${RHANDLERDIR} + @cp --remove-destination lemonldap-ng-handler/example/scripts/purgeLocalCache.cron.d $(RCRONDIR)/lemonldap-ng @rm -rf $$(find $(RHANDLERDIR) -type d -name .svn) install_test_site: @@ -575,6 +577,7 @@ debian-diff: @$(DIFF) lemonldap-ng-portal/example/cdc.pl $(DIFFPREFIX)/var/lib/lemonldap-ng/portal/cdc.pl ||true @# Handler @$(DIFF) lemonldap-ng-handler/lib/Lemonldap/NG/Handler $(DIFFPREFIX)/usr/share/perl5/Lemonldap/NG/Handler ||true + @$(DIFF) lemonldap-ng-portal/example/scripts/purgeLocalCache $(DIFFPREFIX)/usr/share/lemonldap-ng/bin/purgeLocalCache ||true @# Common @$(DIFF) lemonldap-ng-common/lib/Lemonldap/NG/Common $(DIFFPREFIX)/usr/share/perl5/Lemonldap/NG/Common ||true @$(DIFF) lemonldap-ng-common/lib/Lemonldap/NG/Common.pm $(DIFFPREFIX)/usr/share/perl5/Lemonldap/NG/Common.pm ||true @@ -604,6 +607,7 @@ default-diff: @$(DIFF) lemonldap-ng-handler/example/MyHandler.pm $(LMPREFIX)/handler/MyHandler.pm ||true @$(DIFF) lemonldap-ng-handler/example/MyHandlerZimbra.pm $(LMPREFIX)/handler/MyHandlerZimbra.pm ||true @$(DIFF) lemonldap-ng-handler/example/MyHandlerSympa.pm $(LMPREFIX)/handler/MyHandlerSympa.pm ||true + @$(DIFF) lemonldap-ng-portal/example/scripts/purgeLocalCache $(LMPREFIX)/bin/purgeLocalCache ||true @# Common @$(DIFF) lemonldap-ng-common/lib/Lemonldap/NG/Common /usr/local/share/perl/5.10.0/Lemonldap/NG/Common ||true @$(DIFF) lemonldap-ng-common/lib/Lemonldap/NG/Common.pm /usr/local/share/perl/5.10.0/Lemonldap/NG/Common.pm ||true diff --git a/build/lemonldap-ng/debian/liblemonldap-ng-handler-perl.cron.d b/build/lemonldap-ng/debian/liblemonldap-ng-handler-perl.cron.d new file mode 100644 index 000000000..c7139b10e --- /dev/null +++ b/build/lemonldap-ng/debian/liblemonldap-ng-handler-perl.cron.d @@ -0,0 +1,4 @@ +# +# Regular cron jobs for the Lemonldap::NG portal +# +1 * * * * www-data test -x /usr/share/lemonldap-ng/bin/purgeLocalCache && /usr/share/lemonldap-ng/bin/purgeLocalCache diff --git a/build/lemonldap-ng/debian/liblemonldap-ng-handler-perl.install b/build/lemonldap-ng/debian/liblemonldap-ng-handler-perl.install index b5ad65225..8881da851 100644 --- a/build/lemonldap-ng/debian/liblemonldap-ng-handler-perl.install +++ b/build/lemonldap-ng/debian/liblemonldap-ng-handler-perl.install @@ -1,3 +1,4 @@ /usr/share/perl5/Lemonldap/NG/Handler* /usr/share/man/man3/Lemonldap::NG::Handler* /var/lib/lemonldap-ng/test +/usr/share/lemonldap-ng/bin/purgeLocalCache diff --git a/build/lemonldap-ng/debian/rules b/build/lemonldap-ng/debian/rules index fbfc8d8fa..e1fbf0452 100755 --- a/build/lemonldap-ng/debian/rules +++ b/build/lemonldap-ng/debian/rules @@ -101,6 +101,7 @@ binary-indep: build install ln -s ../../liblemonldap-ng-manager-perl/examples manager && \ ln -s ../../liblemonldap-ng-portal-perl/examples portal chmod +x debian/liblemonldap-ng-portal-perl$(LMSHAREDIR)bin/purgeCentralCache + chmod +x debian/liblemonldap-ng-handler-perl$(LMSHAREDIR)bin/purgeLocalCache # dh_installmenu dh_installdebconf # dh_installlogrotate diff --git a/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/Serializer.pm b/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/Serializer.pm index 1ae768d27..7f40fad6b 100644 --- a/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/Serializer.pm +++ b/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/Serializer.pm @@ -101,7 +101,8 @@ sub unserialize { $v =~ s/^'(.*)'$/$1/s; # Manage hashes - if ( $k =~ /^(?x: + if ( + $k =~ /^(?x: applicationList |authChoiceModules |CAS_proxiedServices @@ -124,8 +125,8 @@ sub unserialize { |samlSPMetaDataXML |samlStorageOptions )$/ - and $v ||= {} - and not ref($v) ) + and $v ||= {} and not ref($v) + ) { $conf->{$k} = {}; diff --git a/modules/lemonldap-ng-handler/MANIFEST b/modules/lemonldap-ng-handler/MANIFEST index 1da3713a0..e50c944d8 100644 --- a/modules/lemonldap-ng-handler/MANIFEST +++ b/modules/lemonldap-ng-handler/MANIFEST @@ -6,6 +6,8 @@ example/MyHandlerLog4Perl.pm example/MyHandlerSympa.pm example/MyHandlerZimbra.pm example/MyUpdateCookieHandler.pm +example/scripts/purgeLocalCache +example/scripts/purgeLocalCache.cron.d lib/Lemonldap/NG/Handler.pm lib/Lemonldap/NG/Handler/AuthBasic.pm lib/Lemonldap/NG/Handler/CDA.pm diff --git a/modules/lemonldap-ng-handler/example/scripts/purgeLocalCache b/modules/lemonldap-ng-handler/example/scripts/purgeLocalCache new file mode 100755 index 000000000..3392ca87f --- /dev/null +++ b/modules/lemonldap-ng-handler/example/scripts/purgeLocalCache @@ -0,0 +1,38 @@ +#!/usr/bin/perl +#============================================================================= +# Cleaner for LemonLDAP::NG: purge local handler cache +# +# This module is written to be used by cron to clean old sessions from +# Apache::Session. It does not works with Apache::Session::Memcached +# +# This is part of LemonLDAP::NG product, released under GPL +#============================================================================= + +use Lemonldap::NG::Common::Conf; +use Lemonldap::NG::Common::Conf::Constants; +use strict; + +my $debug = 0; + +#============================================================================= +# Load configuration +#============================================================================= +my $lmconf = Lemonldap::NG::Common::Conf->new() + or die $Lemonldap::NG::Common::Conf::msg; +my $conf = $lmconf->getConf or die "Unable to get configuration ($!)"; +my $localconf = $lmconf->getLocalConf(HANDLERSECTION) + or die "Unable to get local configuration ($!)"; + +if ($localconf) { + $conf->{$_} = $localconf->{$_} foreach ( keys %$localconf ); +} + +print "Configuration loaded\n" if $debug; +exit 0 unless ( $conf->{localStorage} ); +eval "require $conf->{localStorage}"; +$conf->{localStorageOptions}->{namespace} ||= "lemonldap"; +$conf->{localStorageOptions}->{default_expires_in} ||= 600; +my $c = $conf->{localStorage}->new( $conf->{localStorageOptions} ); +$c->Purge(); + +exit 0; diff --git a/modules/lemonldap-ng-handler/example/scripts/purgeLocalCache.cron.d b/modules/lemonldap-ng-handler/example/scripts/purgeLocalCache.cron.d new file mode 100644 index 000000000..337072941 --- /dev/null +++ b/modules/lemonldap-ng-handler/example/scripts/purgeLocalCache.cron.d @@ -0,0 +1,4 @@ +# +# Regular cron jobs for LemonLDAP::NG +# +1 * * * * __APACHEUSER__ [ -x __BINDIR__/purgeLocalCache ] && __BINDIR__/purgeLocalCache diff --git a/modules/lemonldap-ng-portal/example/scripts/purgeCentralCache b/modules/lemonldap-ng-portal/example/scripts/purgeCentralCache index 4d1243f8e..f035473c5 100755 --- a/modules/lemonldap-ng-portal/example/scripts/purgeCentralCache +++ b/modules/lemonldap-ng-portal/example/scripts/purgeCentralCache @@ -19,7 +19,8 @@ my $nb_purged = 0; #============================================================================= # Load configuration #============================================================================= -my $lmconf = Lemonldap::NG::Common::Conf->new(); +my $lmconf = Lemonldap::NG::Common::Conf->new() + or die $Lemonldap::NG::Common::Conf::msg; my $conf = $lmconf->getConf or die "Unable to get configuration ($!)"; my $localconf = $lmconf->getLocalConf(PORTALSECTION) or die "Unable to get local configuration ($!)";