|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
@ -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
|
|
|
|
|
@ -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())
|
|
|
|
|
|