Turn off PXE server when all server has started up

This commit is contained in:
Khue Doan 2020-11-12 23:54:26 +07:00
parent b295e07905
commit 8569d8633e
2 changed files with 14 additions and 1 deletions

4
infra/docker.sh Normal file
View File

@ -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

View File

@ -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")