From 878ea0dfd5e0af358b3d0bbd3a7888b55569d7cf Mon Sep 17 00:00:00 2001 From: Arnaud Morin Date: Tue, 30 May 2023 16:48:32 +0200 Subject: [PATCH] Add a new option to enable signals When running behind a wsgi server like apache/mod_wsgi, neutron should not register on Signals, it will overlap with the Signals registered by the wsgi server. Related-Bug: #2021814 Change-Id: I3c74846a8337d019f1ab6759ebb03f18c3f00238 Signed-off-by: Arnaud Morin --- neutron/conf/common.py | 4 ++++ neutron/plugins/ml2/ovo_rpc.py | 7 +++++-- neutron/plugins/ml2/plugin.py | 3 ++- .../notes/enable_signals-option-706167609c0a5fa7.yaml | 11 +++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/enable_signals-option-706167609c0a5fa7.yaml diff --git a/neutron/conf/common.py b/neutron/conf/common.py index 68616fe78e1..71a8bd5c6a1 100644 --- a/neutron/conf/common.py +++ b/neutron/conf/common.py @@ -165,6 +165,10 @@ core_opts = [ help=_('IPv6 address of this host. If no address is provided ' 'and one cannot be determined, ::1 will be ' 'used.')), + cfg.BoolOpt('enable_signals', default=True, + help=_('If False, neutron-server will not listen for signals ' + 'like SIGINT or SIGTERM. This is useful when running ' + 'behind a WSGI server like apache/mod_wsgi.')), ] core_cli_opts = [ diff --git a/neutron/plugins/ml2/ovo_rpc.py b/neutron/plugins/ml2/ovo_rpc.py index a63998c1698..ffbb02ca38a 100644 --- a/neutron/plugins/ml2/ovo_rpc.py +++ b/neutron/plugins/ml2/ovo_rpc.py @@ -154,10 +154,13 @@ class OVOServerRpcInterface(object): Generates RPC callback notifications on ML2 object changes. """ - def __init__(self): + def __init__(self, enable_signals=True): self._rpc_pusher = resources_rpc.ResourcesPushRpcApi() self._setup_change_handlers() - _setup_change_handlers_cleanup() + # When running behind wsgi server (like apache2/mod_wsgi) + # we should not register signals + if enable_signals: + _setup_change_handlers_cleanup() LOG.debug("ML2 OVO RPC backend initialized.") def _setup_change_handlers(self): diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index fbd72fcb6be..a12a69c6c24 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -407,7 +407,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, self.ovo_notifier = None rpc_workers = conf_service.get_rpc_workers() if rpc_workers is None or rpc_workers >= 1: - self.ovo_notifier = ovo_rpc.OVOServerRpcInterface() + self.ovo_notifier = ovo_rpc.OVOServerRpcInterface( + cfg.CONF.enable_signals) self.notifier = rpc.AgentNotifierApi(topics.AGENT) if cfg.CONF.enable_traditional_dhcp: self.agent_notifiers[const.AGENT_TYPE_DHCP] = ( diff --git a/releasenotes/notes/enable_signals-option-706167609c0a5fa7.yaml b/releasenotes/notes/enable_signals-option-706167609c0a5fa7.yaml new file mode 100644 index 00000000000..40b14924554 --- /dev/null +++ b/releasenotes/notes/enable_signals-option-706167609c0a5fa7.yaml @@ -0,0 +1,11 @@ +--- +features: + - | + A new config option ``enable_signals`` has been added to neutron.conf to + control whether neutron-server registers signal handlers or not (like + SIGTERM, etc). The default value for this new option is True to mimic the + original behavior of registering signal handlers. + The recommendation is to set this option to False when neutron-server is + running behind a WSGI server, because in that situation the signals are + taken over by the WSGI server and neutron will print a stack trace letting + us know that signals cannot be registered.