Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6263617556 for ; Wed, 8 Apr 2015 18:56:17 +0000 (UTC) Received: (qmail 48923 invoked by uid 500); 8 Apr 2015 18:56:16 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 48851 invoked by uid 500); 8 Apr 2015 18:56:16 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 48694 invoked by uid 99); 8 Apr 2015 18:56:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Apr 2015 18:56:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B58A2E17CA; Wed, 8 Apr 2015 18:56:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kxepal@apache.org To: commits@couchdb.apache.org Date: Wed, 08 Apr 2015 18:56:19 -0000 Message-Id: <7c0c14ebff344145bb33faf0b3ee8ebb@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [5/8] couchdb commit: updated refs/heads/developer-preview-2.0 to 9f5ae10 More verbose check nodes for being alive Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/ae65aed4 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/ae65aed4 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/ae65aed4 Branch: refs/heads/developer-preview-2.0 Commit: ae65aed40a1111514d6918619f1d3da2f5247216 Parents: 772add2 Author: Alexander Shorin Authored: Sat Apr 4 23:33:09 2015 +0300 Committer: Alexander Shorin Committed: Wed Apr 8 17:10:04 2015 +0300 ---------------------------------------------------------------------- dev/run | 64 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/ae65aed4/dev/run ---------------------------------------------------------------------- diff --git a/dev/run b/dev/run index fcf9514..501c3cf 100755 --- a/dev/run +++ b/dev/run @@ -50,13 +50,13 @@ def log(msg): sys.stdout.flush() callargs = dict(zip(inspect.getargspec(func).args, args)) callargs.update(kwargs) - print_(msg.format(**callargs) + '... ') + print_(msg.format(**callargs) + ' ... ') try: res = func(*args, **kwargs) except KeyboardInterrupt: print_('ok\n') - except: - print_('failed\n') + except Exception as err: + print_('failed: %s\n' % err) raise else: print_('ok\n') @@ -230,6 +230,7 @@ def hashify(pwd, salt=COMMON_SALT, iterations=10, keylen=20): def startup(ctx): atexit.register(kill_processes, ctx) boot_nodes(ctx) + ensure_all_nodes_alive(ctx) join_nodes(ctx, "127.0.0.1", 15986) @@ -243,30 +244,44 @@ def boot_nodes(ctx): for node in ctx['nodes']: ctx['procs'].append(boot_node(ctx, node)) - ensure_nodes_stated(ctx) - - -@log('Ensure all nodes are run') -def ensure_nodes_stated(ctx): - for _ in range(30): - if all_nodes_alive(ctx): - break - time.sleep(1) - -def all_nodes_alive(ctx): - for num in range(ctx['N']): - local_port, _ = get_ports(num + 1) - url = "http://127.0.0.1:{0}/".format(local_port) - while True: - try: - with contextlib.closing(urlopen(url)): - pass - except IOError: - time.sleep(0.25) +def ensure_all_nodes_alive(ctx): + status = dict((num, False) for num in range(ctx['N'])) + for _ in range(10): + for num in range(ctx['N']): + if status[num]: continue + local_port, _ = get_ports(num + 1) + url = "http://127.0.0.1:{0}/".format(local_port) + try: + check_node_alive(url) + except: + pass + else: + status[num] = True + if all(status.values()): + return + time.sleep(1) + if not all(status.values()): + print('Failed to start all the nodes.' + ' Check the dev/logs/*.log for errors.') + sys.exit(1) + + +@log('Check node at {url}') +def check_node_alive(url): + error = None + for _ in range(10): + try: + with contextlib.closing(urlopen(url)): + pass + except Exception as exc: + error = exc + time.sleep(1) + else: break - return True + if error is not None: + raise error @log('Start node {node}') @@ -332,6 +347,7 @@ def run_command(ctx, cmd): def reboot_nodes(ctx): kill_processes(ctx) boot_nodes(ctx) + ensure_all_nodes_alive(ctx) if __name__ == "__main__":