Skip to content

Commit

Permalink
make the reboots explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Sep 30, 2022
1 parent 86f90cf commit d319237
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 14 deletions.
3 changes: 0 additions & 3 deletions provision-guest-additions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,3 @@ else
echo 'ERROR: Unknown VM host.'
exit 1
fi

# reboot.
nohup bash -c "ps -eo pid,comm | awk '/sshd/{print \$1}' | xargs kill; sync; reboot"
4 changes: 0 additions & 4 deletions provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ set -euxo pipefail
# wait for cloud-init to finish.
cloud-init status --long --wait

# let the sudo group members use root permissions without a password.
# NB d-i automatically adds vagrant into the sudo group.
sed -i -E 's,^%sudo\s+.+,%sudo ALL=(ALL) NOPASSWD:ALL,g' /etc/sudoers

# install the vagrant public key.
# NB vagrant will replace it on the first run.
install -d -m 700 /home/vagrant/.ssh
Expand Down
4 changes: 4 additions & 0 deletions reboot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -euxo pipefail

reboot --force
27 changes: 25 additions & 2 deletions ubuntu-vsphere.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,34 @@ build {
sources = ["source.vsphere-iso.ubuntu-amd64"]

provisioner "shell" {
execute_command = "echo vagrant | sudo -S bash {{ .Path }}"
expect_disconnect = true
execute_command = "echo vagrant | sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"upgrade.sh",
]
}

provisioner "shell" {
expect_disconnect = true
scripts = [
"reboot.sh",
]
}

provisioner "shell" {
scripts = [
"provision-guest-additions.sh",
]
}

provisioner "shell" {
expect_disconnect = true
scripts = [
"reboot.sh",
]
}

provisioner "shell" {
scripts = [
"provision.sh",
]
}
Expand Down
31 changes: 29 additions & 2 deletions ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,38 @@ build {
]

provisioner "shell" {
execute_command = "echo vagrant | sudo -S {{ .Vars }} bash {{ .Path }}"
expect_disconnect = true
execute_command = "echo vagrant | sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"upgrade.sh",
]
}

provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
expect_disconnect = true
scripts = [
"reboot.sh",
]
}

provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"provision-guest-additions.sh",
]
}

provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
expect_disconnect = true
scripts = [
"reboot.sh",
]
}

provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"provision.sh",
]
}
Expand Down
7 changes: 4 additions & 3 deletions upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ set -euxo pipefail
# wait for cloud-init to finish.
cloud-init status --long --wait

# let the sudo group members use root permissions without a password.
# NB d-i automatically added the vagrant user into the sudo group.
sed -i -E 's,^%sudo\s+.+,%sudo ALL=(ALL) NOPASSWD:ALL,g' /etc/sudoers

# configure apt for non-interactive mode.
export DEBIAN_FRONTEND=noninteractive

# upgrade.
apt-get update
apt-get dist-upgrade -y

# reboot.
nohup bash -c "ps -eo pid,comm | awk '/sshd/{print \$1}' | xargs kill; sync; reboot"

0 comments on commit d319237

Please sign in to comment.