From ab683b43c63612b01c92ab186845e33cd1dbdf80 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 10 Apr 2024 10:54:48 +0200 Subject: [PATCH] Bug 30897: Gracefully restart plack after plugin install/remove --- Koha/Plugins.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index d93e9fe40fc..94ff5e991a5 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -26,6 +26,7 @@ use Module::Load::Conditional qw( can_load ); use Module::Load; use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/; use Try::Tiny; +use POSIX qw(getpid); use C4::Context; use C4::Output; @@ -312,6 +313,8 @@ sub InstallPlugins { Koha::Cache::Memory::Lite->clear_from_cache(ENABLED_PLUGINS_CACHE_KEY); + $self->_restart_after_change(); + return @plugins; } @@ -354,6 +357,24 @@ sub RemovePlugins { Koha::Plugins::Datas->search($cond)->update( { plugin_value => 0 } ); Koha::Cache::Memory::Lite->clear_from_cache( Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY ); } + + $class->_restart_after_change(); +} + +sub _restart_after_change { + my ( $class, $params ) = @_; + + my $parent_pid = getpid(); + my $ppid = getppid(); # Get the parent process ID + + # If the current process is not Plack parent, find the parent process recursively + while ($parent_pid != $ppid) { + $parent_pid = $ppid; + $ppid = getppid(); + } + + # Send SIGUSR1 signal to Plack parent process for graceful restart + kill 'HUP', $parent_pid; } 1; -- 2.44.0