Skip to content

Commit

Permalink
Setup signal handler before creating dcs
Browse files Browse the repository at this point in the history
Otherwise it was swallowing SysExit exception in an infinite loop.
  • Loading branch information
Alexander Kukushkin committed Jun 22, 2016
1 parent 5683880 commit 44433c2
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions patroni/__init__.py
Expand Up @@ -18,6 +18,8 @@
class Patroni(object):

def __init__(self):
self.setup_signal_handlers()

self.version = __version__
self.config = Config()
self.dcs = get_dcs(self.config)
Expand All @@ -31,10 +33,6 @@ def __init__(self):
self.nap_time = self.config['loop_wait']
self.next_run = time.time()

self._reload_config_scheduled = False
self._received_sighup = False
self._received_sigterm = False

def load_dynamic_configuration(self):
while True:
try:
Expand All @@ -51,6 +49,10 @@ def get_tags(self):
return {tag: value for tag, value in self.config.get('tags', {}).items()
if tag not in ('clonefrom', 'nofailover', 'noloadbalance') or value}

@property
def nofailover(self):
return self.tags.get('nofailover', False)

def reload_config(self):
try:
self.tags = self.get_tags()
Expand All @@ -62,6 +64,10 @@ def reload_config(self):
except Exception:
logger.exception('Failed to reload config_file=%s', self.config.config_file)

@property
def replicatefrom(self):
return self.tags.get('replicatefrom')

def sighup_handler(self, *args):
self._received_sighup = True

Expand All @@ -74,14 +80,6 @@ def sigterm_handler(self, *args):
def noloadbalance(self):
return self.tags.get('noloadbalance', False)

@property
def nofailover(self):
return self.tags.get('nofailover', False)

@property
def replicatefrom(self):
return self.tags.get('replicatefrom')

def schedule_next_run(self):
self.next_run += self.nap_time
current_time = time.time()
Expand Down Expand Up @@ -114,6 +112,8 @@ def run(self):
self.schedule_next_run()

def setup_signal_handlers(self):
self._received_sighup = False
self._received_sigterm = False
signal.signal(signal.SIGHUP, self.sighup_handler)
signal.signal(signal.SIGTERM, self.sigterm_handler)
signal.signal(signal.SIGCHLD, sigchld_handler)
Expand All @@ -124,7 +124,6 @@ def main():
logging.getLogger('requests').setLevel(logging.WARNING)

patroni = Patroni()
patroni.setup_signal_handlers()
try:
patroni.run()
except KeyboardInterrupt:
Expand Down

0 comments on commit 44433c2

Please sign in to comment.