From cf68368eea530281e70c2d9b20ca82f72587e25d Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Mon, 7 Feb 2022 09:11:07 +0100 Subject: [PATCH] Reduce reboot time --- agents.tf | 7 ++++++- locals.tf | 8 ++------ master.tf | 7 ++++++- servers.tf | 7 ++++++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/agents.tf b/agents.tf index cb46e09..45caa3a 100644 --- a/agents.tf +++ b/agents.tf @@ -43,9 +43,14 @@ resource "hcloud_server" "agents" { } } + # Issue a reboot command + provisioner "local-exec" { + command = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root ${self.ipv4_address} '(sleep 2; reboot)&'; sleep 3" + } + # Wait for MicroOS to reboot and be ready provisioner "local-exec" { - command = "sleep 60 && ping ${self.ipv4_address} | grep --line-buffered 'bytes from' | head -1 && sleep 60" + command = "until ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root -o ConnectTimeout=2 ${self.ipv4_address} true; do sleep 1; done" } # Generating and uploading the angent.conf file diff --git a/locals.tf b/locals.tf index d81f8a7..bef6674 100644 --- a/locals.tf +++ b/locals.tf @@ -17,18 +17,14 @@ locals { "aria2c --follow-metalink=mem https://download.opensuse.org/tumbleweed/appliances/openSUSE-MicroOS.x86_64-k3s-kvm-and-xen.qcow2.meta4", "qemu-img convert -p -f qcow2 -O host_device $(ls -a | grep -ie '^opensuse.*microos.*k3s.*qcow2$') /dev/sda", "sgdisk -e /dev/sda", - "partprobe /dev/sda", "parted -s /dev/sda resizepart 4 99%", "parted -s /dev/sda mkpart primary ext2 99% 100%", - "udevadm settle", + "partprobe /dev/sda", "mount /dev/sda4 /mnt/ && btrfs filesystem resize max /mnt && umount /mnt", "mke2fs -L ignition /dev/sda5", "mount /dev/sda5 /mnt", "mkdir /mnt/ignition", "cp /root/config.ign /mnt/ignition/config.ign", - "umount /mnt", - "shutdown -r +1", - "sleep 1", - "exit 0" + "umount /mnt" ] } diff --git a/master.tf b/master.tf index 3a29f06..bd5efba 100644 --- a/master.tf +++ b/master.tf @@ -41,9 +41,14 @@ resource "hcloud_server" "first_control_plane" { } } + # Issue a reboot command + provisioner "local-exec" { + command = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root ${self.ipv4_address} '(sleep 2; reboot)&'; sleep 3" + } + # Wait for MicroOS to reboot and be ready provisioner "local-exec" { - command = "sleep 60 && ping ${self.ipv4_address} | grep --line-buffered 'bytes from' | head -1 && sleep 60" + command = "until ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root -o ConnectTimeout=2 ${self.ipv4_address} true; do sleep 1; done" } # Generating k3s master config file diff --git a/servers.tf b/servers.tf index da09a17..57393c5 100644 --- a/servers.tf +++ b/servers.tf @@ -42,9 +42,14 @@ resource "hcloud_server" "control_planes" { } } + # Issue a reboot command + provisioner "local-exec" { + command = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root ${self.ipv4_address} '(sleep 2; reboot)&'; sleep 3" + } + # Wait for MicroOS to reboot and be ready provisioner "local-exec" { - command = "sleep 60 && ping ${self.ipv4_address} | grep --line-buffered 'bytes from' | head -1 && sleep 60" + command = "until ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l root -o ConnectTimeout=2 ${self.ipv4_address} true; do sleep 1; done" } # Generating k3s server config file