Skip to content

Commit

Permalink
parallels/vmware: don't wait for shutdown command.
Browse files Browse the repository at this point in the history
Resolves #4134

replaces/ closes #4379

Leaving Hyper-V builder alone for now until we can get a case that reproduces.
  • Loading branch information
mwhooker committed Jan 20, 2017
1 parent 1109073 commit f1175c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
15 changes: 12 additions & 3 deletions builder/parallels/common/step_shutdown.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"bytes"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -36,9 +37,15 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction {
if s.Command != "" {
ui.Say("Gracefully halting virtual machine...")
log.Printf("Executing shutdown command: %s", s.Command)
cmd := &packer.RemoteCmd{Command: s.Command}
if err := cmd.StartWithUi(comm, ui); err != nil {
err = fmt.Errorf("Failed to send shutdown command: %s", err)

var stdout, stderr bytes.Buffer
cmd := &packer.RemoteCmd{
Command: s.Command,
Stdout: &stdout,
Stderr: &stderr,
}
if err := comm.Start(cmd); err != nil {
err := fmt.Errorf("Failed to send shutdown command: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -55,6 +62,8 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction {

select {
case <-shutdownTimer:
log.Printf("Shutdown stdout: %s", stdout.String())
log.Printf("Shutdown stderr: %s", stderr.String())
err := errors.New("Timeout while waiting for machine to shut down.")
state.Put("error", err)
ui.Error(err.Error())
Expand Down
10 changes: 2 additions & 8 deletions builder/vmware/common/step_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ 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())

// Wait for the machine to actually shut down
log.Printf("Waiting max %s for shutdown to complete", s.Timeout)
shutdownTimer := time.After(s.Timeout)
Expand All @@ -76,6 +68,8 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction {

select {
case <-shutdownTimer:
log.Printf("Shutdown stdout: %s", stdout.String())
log.Printf("Shutdown stderr: %s", stderr.String())
err := errors.New("Timeout while waiting for machine to shut down.")
state.Put("error", err)
ui.Error(err.Error())
Expand Down
2 changes: 1 addition & 1 deletion packer/communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/mitchellh/iochan"
)

// CmdDisconnect is a sentry value to indicate a RemoteCmd
// CmdDisconnect is a sentinel value to indicate a RemoteCmd
// exited because the remote side disconnected us.
const CmdDisconnect int = 2300218

Expand Down

0 comments on commit f1175c1

Please sign in to comment.