From 60fc1f64fabd86c38846c76785255c523a98b331 Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Wed, 25 Jun 2014 15:06:13 +0200 Subject: [PATCH] Exit rpc_loop when SIGTERM is recieved in ovs-agent Previously ovs-agent exited with exit code 1 after SIGTERM was received. SIGTERM should shutdown agent gracefully and exit code should be 0. Closes-Bug: #1334264 Change-Id: I23e81cee5ae9e9fdabbe1377420b0902f47be8a7 --- .../plugins/openvswitch/agent/ovs_neutron_agent.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py index ccc5ff246..58527fada 100644 --- a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py @@ -213,6 +213,7 @@ class OVSNeutronAgent(n_rpc.RpcCallback, root_helper) # Initialize iteration counter self.iter_num = 0 + self.run_daemon_loop = True def _check_arp_responder_support(self): '''Check if OVS supports to modify ARP headers. @@ -1313,7 +1314,7 @@ class OVSNeutronAgent(n_rpc.RpcCallback, ancillary_ports = set() tunnel_sync = True ovs_restarted = False - while True: + while self.run_daemon_loop: start = time.time() port_stats = {'regular': {'added': 0, 'updated': 0, @@ -1439,9 +1440,9 @@ class OVSNeutronAgent(n_rpc.RpcCallback, self.rpc_loop(polling_manager=pm) - -def handle_sigterm(signum, frame): - sys.exit(1) + def _handle_sigterm(self, signum, frame): + LOG.debug("Agent caught SIGTERM, quitting daemon loop.") + self.run_daemon_loop = False def create_agent_config_map(config): @@ -1504,12 +1505,11 @@ def main(): cfg.CONF.set_default('ip_lib_force_root', True) agent = OVSNeutronAgent(**agent_config) - signal.signal(signal.SIGTERM, handle_sigterm) + signal.signal(signal.SIGTERM, agent._handle_sigterm) # Start everything. LOG.info(_("Agent initialized successfully, now running... ")) agent.daemon_loop() - sys.exit(0) if __name__ == "__main__": -- 2.45.2