From 36473f390cac58ac81bf710aecf883cb0c37be87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= <valtri@civ.zcu.cz> Date: Tue, 22 Dec 2020 21:28:14 +0100 Subject: [PATCH] Poor-man implementation of waiting --- launch.sh | 4 ---- orchestrate.py | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/launch.sh b/launch.sh index f826cd2..417f9bb 100755 --- a/launch.sh +++ b/launch.sh @@ -1,8 +1,4 @@ #! /bin/sh -xe ./terraform apply -auto-approve "$@" ./terraform output -json > config.json -echo 'Sleeping...' -sleep 60 -echo "Press <ENTER> to continue..." -read x ./orchestrate.py -c config.json diff --git a/orchestrate.py b/orchestrate.py index 04ddef4..0f8d796 100755 --- a/orchestrate.py +++ b/orchestrate.py @@ -6,8 +6,9 @@ import json import os import subprocess import sys +import time -DEFAULT_ACTIONS = ['files', 'init', 'check'] +DEFAULT_ACTIONS = ['files', 'ping', 'init', 'wait'] parser = argparse.ArgumentParser(description='terraform cluster orchestrator') parser.add_argument('-c', '--config', @@ -89,6 +90,31 @@ ff02::2 ip6-allrouters if component: component.action('files') +if 'ping' in args.actions: + print('== ping ==') + if not args.dry_run: + print('-> (ping) ', end='') + ret = None + while ret is None or ret != 0: + print('.', end='') + ret = subprocess.call(['ping', '-c', '1', '-i', '2', master_ip]) + print('') + cmd = ['ssh-keygen', '-R', master_ip] + print('-> %s' % ' '.join(cmd)) + subprocess.run(cmd) + cmd = ['ssh', '%s@%s' % (user, master_ip), '-o', 'ConnectTimeout=5', '-o', + 'StrictHostKeyChecking=no', ':'] + ret = None + while ret is None or ret != 0: + print('-> %s' % ' '.join(cmd)) + ret = subprocess.call(cmd) + time.sleep(2) + print('') + print('-> sleep %d' % 10 + 5 * n) + time.sleep(10 + 5 * n) + if component: + component.action('ping') + if 'init' in args.actions: print('== init ==') @@ -122,11 +148,13 @@ if 'init' in args.actions: if component: component.action('init') -if 'check' in args.actions: - print('== check ==') +if 'wait' in args.actions: + print('== wait ==') commands = [ - ['ansible', '-i', './inventory', '-m', 'command', '-a', 'uname -a', 'all'] + ['ansible', '-i', './inventory', '-m', 'command', '-a', 'uname -a', 'all'], + ['ansible', '-i', './inventory', '-m', 'shell', '-a', + 'while ! test -f /var/lib/cloud/instance/boot-finished; do sleep 2; done', 'all'], ] for cmd in commands: @@ -134,4 +162,4 @@ if 'check' in args.actions: if not args.dry_run: subprocess.run(cmd) if component: - component.action('check') + component.action('wait') -- GitLab