From afe1a2c92cf5a75607fe12d87ad80e56029fc139 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Fri, 18 Sep 2015 12:41:36 +0200 Subject: [PATCH] During shutdown sigterm is send to all processes every second First time is triggers some shutdown mechanisms in a patroni, but the second one just terminates patroni. Solution is pretty simple, we need to ignore all other sigterms which are coming after the first one. --- patroni/__init__.py | 1 + patroni/utils.py | 1 + tests/test_patroni.py | 3 +++ 3 files changed, 5 insertions(+) diff --git a/patroni/__init__.py b/patroni/__init__.py index c190e2de..5a8588ce 100644 --- a/patroni/__init__.py +++ b/patroni/__init__.py @@ -126,6 +126,7 @@ def main(): except KeyboardInterrupt: pass finally: + patroni.api.shutdown() patroni.touch_member(patroni.shutdown_member_ttl) # schedule member removal patroni.postgresql.stop() patroni.ha.dcs.delete_leader() diff --git a/patroni/utils.py b/patroni/utils.py index 45ada864..898b058e 100644 --- a/patroni/utils.py +++ b/patroni/utils.py @@ -46,6 +46,7 @@ def calculate_ttl(expiration): def sigterm_handler(signo, stack_frame): + signal.signal(signal.SIGTERM, signal.SIG_IGN) sys.exit() diff --git a/tests/test_patroni.py b/tests/test_patroni.py index 65293d03..7481a6fd 100644 --- a/tests/test_patroni.py +++ b/tests/test_patroni.py @@ -40,6 +40,9 @@ def keyboard_interrupt(*args): class Mock_BaseServer__is_shut_down: + def wait(self): + pass + def set(self): pass