From 0a0487d8841ec8f57c5795827fb3aecae1a9a62b 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 This patch adds a graceful plack restart to the plugin install/uninstall routine to fully allow plugin install to work via the staff client. Test plan 1. list your worker processes with something like htop 2. install a plugin https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases 3. note that the PIDs of the workers stay the same and no sign of restart (no PID changes and no CPU activity that the workers would have if they were starting) 4. apply patches and restart services 5. unistall plugin 6. notice worker restart 7. install plugin 8. notice worker restart 9. downgrade plugin 10. notice worker restart 11. upgrade plugin 12. notice worker restart 13. disable and enable plugin 14. *no restart* Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- Koha/Plugins.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index d93e9fe40f..cea8a5f9ec 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.39.2