From 8569d8633eef51c9a17c851e4064a78747c8a61c Mon Sep 17 00:00:00 2001 From: Khue Doan Date: Thu, 12 Nov 2020 23:54:26 +0700 Subject: [PATCH] Turn off PXE server when all server has started up --- infra/docker.sh | 4 ++++ infra/scripts/reset.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 infra/docker.sh diff --git a/infra/docker.sh b/infra/docker.sh new file mode 100644 index 00000000..ab163e92 --- /dev/null +++ b/infra/docker.sh @@ -0,0 +1,4 @@ +yum install -y yum-utils +yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo +yum install -y docker-ce docker-ce-cli containerd.io +systemctl enable docker diff --git a/infra/scripts/reset.py b/infra/scripts/reset.py index 9e7175d2..ea89d32d 100755 --- a/infra/scripts/reset.py +++ b/infra/scripts/reset.py @@ -35,10 +35,13 @@ nodes = [ def is_alive(node): return os.system(f"ping -c 1 {node['ip']}") == 0 +def is_ready(node): + return os.system(f"ssh -o StrictHostKeyChecking=no {user}@{node['ip']} exit") == 0 + def poweroff(node): if is_alive(node): print(f"Poweroff {node['name']}") - os.system(f"ssh {user}@{node['ip']} poweroff") + os.system(f"ssh -o StrictHostKeyChecking=no {user}@{node['ip']} poweroff") else: print(f"Node {node['name']} is already dead!") @@ -57,3 +60,9 @@ if __name__ == "__main__": for node in nodes: wake(node) + + while not all(is_ready(node) for node in nodes): + print("Waiting for all servers to start up...") + time.sleep(10) + + os.system(f"docker-compose down")