From f9f47c5bbba520e550c39d7039ca39806e4f49ad Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Fri, 21 Oct 2016 22:26:34 -0700 Subject: [PATCH 1/3] fix shell disconnect error when shutting down vmware --- builder/vmware/common/step_shutdown.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builder/vmware/common/step_shutdown.go b/builder/vmware/common/step_shutdown.go index 5aad45fd0..7ff443152 100644 --- a/builder/vmware/common/step_shutdown.go +++ b/builder/vmware/common/step_shutdown.go @@ -61,7 +61,8 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction { cmd.Wait() // If the command failed to run, notify the user in some way. - if cmd.ExitStatus != 0 { + // Ignores disconnect errors. + if cmd.ExitStatus != packer.CmdDisconnect && cmd.ExitStatus != 0 { state.Put("error", fmt.Errorf( "Shutdown command has non-zero exit status.\n\nStdout: %s\n\nStderr: %s", stdout.String(), stderr.String())) From e9a5d05a2f48d4cb52ef38509b9510778c5370b0 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Fri, 21 Oct 2016 22:41:45 -0700 Subject: [PATCH 2/3] builder/vmware: Ignore shutdown errors Resolves issue where `shutdown_command` would error because the remote side disconnected, which we should have expected and ignored. --- builder/vmware/common/step_shutdown.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/builder/vmware/common/step_shutdown.go b/builder/vmware/common/step_shutdown.go index 7ff443152..387e59663 100644 --- a/builder/vmware/common/step_shutdown.go +++ b/builder/vmware/common/step_shutdown.go @@ -57,18 +57,6 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } - // Wait for the command to run - cmd.Wait() - - // If the command failed to run, notify the user in some way. - // Ignores disconnect errors. - if cmd.ExitStatus != packer.CmdDisconnect && cmd.ExitStatus != 0 { - state.Put("error", fmt.Errorf( - "Shutdown command has non-zero exit status.\n\nStdout: %s\n\nStderr: %s", - stdout.String(), stderr.String())) - return multistep.ActionHalt - } - log.Printf("Shutdown stdout: %s", stdout.String()) log.Printf("Shutdown stderr: %s", stderr.String()) From d6bed794293b8794ff9c34d277722efc7a35588e Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Sat, 22 Oct 2016 10:33:27 -0700 Subject: [PATCH 3/3] wait for shutdown command to end so we get stderr/out --- builder/vmware/common/step_shutdown.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builder/vmware/common/step_shutdown.go b/builder/vmware/common/step_shutdown.go index 387e59663..666649993 100644 --- a/builder/vmware/common/step_shutdown.go +++ b/builder/vmware/common/step_shutdown.go @@ -57,6 +57,11 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } + // Wait for the command to run so we can print std{err,out} + // We don't care if the command errored, since we'll notice + // if the vm didn't shut down. + cmd.Wait() + log.Printf("Shutdown stdout: %s", stdout.String()) log.Printf("Shutdown stderr: %s", stderr.String())