From 6f747f94258b35f74c4fccb11c066f2933de5dd7 Mon Sep 17 00:00:00 2001 From: Aaron Bull Schaefer Date: Thu, 26 Sep 2013 11:29:28 -0700 Subject: [PATCH] Add a workaround for the shutdown race condition http://comments.gmane.org/gmane.linux.arch.general/48739 Basically systemd kills the networking before it kills ssh sessions, and Packer will try and wait for a 0 exit code after the shutdown command to confirm that it worked. Things happen too quickly with systemd, and so Packer complains when gracefully halting the machine that: "Build 'vmware' errored: Shutdown command has non-zero exit status." This workaround just adds a standard systemd timer to the poweroff command so it has a one second delay, which is long enough for the 0 exit code to return and signal a successful graceful halt. --- arch-template.json | 2 +- install.sh | 2 ++ poweroff.timer | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 poweroff.timer diff --git a/arch-template.json b/arch-template.json index 1726cf9..9bf0a6b 100644 --- a/arch-template.json +++ b/arch-template.json @@ -14,7 +14,7 @@ "disk_size": 20480, "ssh_username": "root", "ssh_password": "vagrant", - "shutdown_command": "systemctl poweroff" + "shutdown_command": "systemctl start poweroff.timer" } ], "post-processors": [ diff --git a/install.sh b/install.sh index 384aa9d..5d0dc92 100644 --- a/install.sh +++ b/install.sh @@ -66,6 +66,8 @@ cat <<-EOF > "${TARGET_DIR}${CONFIG_SCRIPT}" /usr/bin/curl --output /home/vagrant/.ssh/authorized_keys https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub /usr/bin/chown vagrant:users /home/vagrant/.ssh/authorized_keys /usr/bin/chmod 0600 /home/vagrant/.ssh/authorized_keys + # workaround for shutdown race condition: http://comments.gmane.org/gmane.linux.arch.general/48739 + /usr/bin/curl --output /etc/systemd/system/poweroff.timer https://raw.github.com/elasticdog/packer-arch/master/poweroff.timer # clean up /usr/bin/pacman -Rcns --noconfirm gptfdisk diff --git a/poweroff.timer b/poweroff.timer new file mode 100644 index 0000000..2310ffb --- /dev/null +++ b/poweroff.timer @@ -0,0 +1,6 @@ +[Unit] +Description=Delayed poweroff + +[Timer] +OnActiveSec=1 +Unit=poweroff.target