From 1b5f86ea5cf5374730d006a24c59a1c03e973175 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 14 Mar 2019 15:52:26 -0300 Subject: [PATCH] Bug 22473: Example of watcher to invalidate config cache - V4 Test plan: perl watchfile.pl then update the config Note that we do not handle everything, for instance the DB credentials will not be taken into account. I guess we could call C4::Context->dbh({ new => 1 }) as well. --- watchfile.pl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 watchfile.pl diff --git a/watchfile.pl b/watchfile.pl new file mode 100644 index 0000000000..d9e6de127b --- /dev/null +++ b/watchfile.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use C4::Context; +use Koha::Caches; + +use Event; +use Linux::Inotify2; + +my $inotify = Linux::Inotify2->new; + +Event->io (fd => $inotify->fileno, poll => 'r', cb => sub { $inotify->poll }); + +our $filename = '/etc/koha/sites/kohadev/koha-conf.xml'; + +sub cb { + my $e = shift; + + # Flushing the config + Koha::Caches->get_instance('config')->flush_all; + C4::Context->new; + + # We need to cancel the watcher and recreate it as the file has been modified (usually delete+creation) + $e->w->cancel; + + $inotify->watch ($filename, IN_MODIFY, \&cb); +} + +$inotify->watch ($filename, IN_MODIFY, \&cb); + +Event::loop; -- 2.11.0