]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: supervisord plugin: forwarding SIGHUP to the manager
authorVasek Sraier <git@vakabus.cz>
Thu, 27 Oct 2022 20:36:21 +0000 (22:36 +0200)
committerVasek Sraier <git@vakabus.cz>
Sat, 3 Dec 2022 10:31:10 +0000 (11:31 +0100)
manager/knot_resolver_manager/kresd_controller/supervisord/plugin/manager_integration.py [moved from manager/knot_resolver_manager/kresd_controller/supervisord/plugin/manager_lifecycle_monitor.py with 82% similarity]
manager/knot_resolver_manager/kresd_controller/supervisord/supervisord.conf.j2

similarity index 82%
rename from manager/knot_resolver_manager/kresd_controller/supervisord/plugin/manager_lifecycle_monitor.py
rename to manager/knot_resolver_manager/kresd_controller/supervisord/plugin/manager_integration.py
index b115dcc896223d0ca0b31ed25a68c92884805b41..81115617970c91a8b523e580b06af4dd5d749d47 100644 (file)
@@ -2,10 +2,12 @@
 # pylint: disable=protected-access
 import atexit
 import os
+import signal
 from typing import Any, Optional
 
 from supervisor.compat import as_string
 from supervisor.events import ProcessStateFatalEvent, ProcessStateRunningEvent, ProcessStateStartingEvent, subscribe
+from supervisor.options import ServerOptions
 from supervisor.process import Subprocess
 from supervisor.states import SupervisorStates
 from supervisor.supervisord import Supervisor
@@ -49,6 +51,17 @@ def check_for_runnning_manager(event: ProcessStateRunningEvent) -> None:
         systemd_notify(READY="1", STATUS="Ready")
 
 
+def ServerOptions_get_signal(self):
+    sig = self.signal_receiver.get_signal()
+    if sig == signal.SIGHUP and superd is not None:
+        superd.options.logger.info("received SIGHUP, forwarding to the process 'manager'")
+        manager_pid = superd.process_groups["manager"].processes["manager"].pid
+        os.kill(manager_pid, signal.SIGHUP)
+        return None
+
+    return sig
+
+
 def inject(supervisord: Supervisor, **_config: Any) -> Any:  # pylint: disable=useless-return
     global superd
     superd = supervisord
@@ -63,6 +76,9 @@ def inject(supervisord: Supervisor, **_config: Any) -> Any:  # pylint: disable=u
     subscribe(ProcessStateStartingEvent, check_for_starting_manager)
     subscribe(ProcessStateRunningEvent, check_for_runnning_manager)
 
+    # forward SIGHUP to manager
+    ServerOptions.get_signal = ServerOptions_get_signal
+
     # this method is called by supervisord when loading the plugin,
     # it should return XML-RPC object, which we don't care about
     # That's why why are returning just None
index 75b4f6b38f004e25532844f0fcff23c1b0c52d60..29116f09becbe0332f1f27981fbb32042885a2e2 100644 (file)
@@ -24,8 +24,8 @@ serverurl = unix://{{ config.unix_http_server }}
 supervisor.rpcinterface_factory = knot_resolver_manager.kresd_controller.supervisord.plugin.patch_logger:inject
 target = {{ config.target }}
 
-[rpcinterface:manager_lifecycle_monitor]
-supervisor.rpcinterface_factory = knot_resolver_manager.kresd_controller.supervisord.plugin.manager_lifecycle_monitor:inject
+[rpcinterface:manager_integration]
+supervisor.rpcinterface_factory = knot_resolver_manager.kresd_controller.supervisord.plugin.manager_integration:inject
 
 [rpcinterface:sd_notify]
 supervisor.rpcinterface_factory = knot_resolver_manager.kresd_controller.supervisord.plugin.sd_notify:inject