From 0b4c0758e98706e126ec8d40f01d8f25a7524f0d Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 25 Jul 2013 23:15:47 -0700 Subject: [PATCH] The previous check wasn't handling it already running. Change-Id: I43ce52f64e907f832dd91a74a3834fee04194a32 --- anvil/components/rabbit.py | 21 +++++++++++++++++---- anvil/utils.py | 4 ++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/anvil/components/rabbit.py b/anvil/components/rabbit.py index e8171e71..1fedce1d 100644 --- a/anvil/components/rabbit.py +++ b/anvil/components/rabbit.py @@ -79,11 +79,24 @@ class RabbitInstaller(binstall.PkgInstallComponent): class RabbitRuntime(bruntime.ProgramRuntime): def start(self): - if self.statii()[0].status != bruntime.STATUS_STARTED: - self._run_action('start') + + def is_active(): + status = self.statii()[0].status + if status == bruntime.STATUS_STARTED: + return True + return False + + if is_active(): return 1 - else: - raise RuntimeError('Failed to start rabbit-mq') + + self._run_action('start') + for sleep_secs in utils.ExponentialBackoff(): + LOG.info("Sleeping for %s seconds, rabbit-mq is still not active.", + sleep_secs) + sh.sleep(sleep_secs) + if is_active(): + return 1 + raise RuntimeError('Failed to start rabbit-mq') @property def applications(self): diff --git a/anvil/utils.py b/anvil/utils.py index cb3d7b11..b5f5ea5a 100644 --- a/anvil/utils.py +++ b/anvil/utils.py @@ -93,7 +93,7 @@ LOG = logging.getLogger(__name__) class ExponentialBackoff(object): - def __init__(self, start, attempts): + def __init__(self, attempts=5, start=1.3): self.start = start self.attempts = attempts @@ -168,7 +168,7 @@ def wait_for_url(url, max_attempts=5): excps = [] attempts = 0 - for sleep_time in ExponentialBackoff(1.3, max_attempts): + for sleep_time in ExponentialBackoff(attempts=max_attempts): attempts += 1 try: with contextlib.closing(urllib2.urlopen(urllib2.Request(url))) as req: