builder/vmware: error if shutdown command failed
This commit is contained in:
parent
56aff48143
commit
0fdf9b09c9
@ -5,6 +5,10 @@ FEATURES:
|
|||||||
* VirtualBox and VMware can now have `floppy_files` specified to attach
|
* VirtualBox and VMware can now have `floppy_files` specified to attach
|
||||||
floppy disks when booting. This allows for unattended Windows installs.
|
floppy disks when booting. This allows for unattended Windows installs.
|
||||||
|
|
||||||
|
IMPROVEMENTS:
|
||||||
|
|
||||||
|
* vmware: error if shutdown command has non-zero exit status.
|
||||||
|
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
|
||||||
* core: UI messages are now properly prefixed with spaces again.
|
* core: UI messages are now properly prefixed with spaces again.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package vmware
|
package vmware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
@ -35,7 +36,13 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
|
|||||||
if config.ShutdownCommand != "" {
|
if config.ShutdownCommand != "" {
|
||||||
ui.Say("Gracefully halting virtual machine...")
|
ui.Say("Gracefully halting virtual machine...")
|
||||||
log.Printf("Executing shutdown command: %s", config.ShutdownCommand)
|
log.Printf("Executing shutdown command: %s", config.ShutdownCommand)
|
||||||
cmd := &packer.RemoteCmd{Command: config.ShutdownCommand}
|
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
cmd := &packer.RemoteCmd{
|
||||||
|
Command: config.ShutdownCommand,
|
||||||
|
Stdout: &stdout,
|
||||||
|
Stderr: &stderr,
|
||||||
|
}
|
||||||
if err := comm.Start(cmd); err != nil {
|
if err := comm.Start(cmd); err != nil {
|
||||||
err := fmt.Errorf("Failed to send shutdown command: %s", err)
|
err := fmt.Errorf("Failed to send shutdown command: %s", err)
|
||||||
state["error"] = err
|
state["error"] = err
|
||||||
@ -46,6 +53,17 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
|
|||||||
// Wait for the command to run
|
// Wait for the command to run
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
|
|
||||||
|
// If the command failed to run, notify the user in some way.
|
||||||
|
if cmd.ExitStatus != 0 {
|
||||||
|
state["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())
|
||||||
|
|
||||||
// Wait for the machine to actually shut down
|
// Wait for the machine to actually shut down
|
||||||
log.Printf("Waiting max %s for shutdown to complete", config.ShutdownTimeout)
|
log.Printf("Waiting max %s for shutdown to complete", config.ShutdownTimeout)
|
||||||
shutdownTimer := time.After(config.ShutdownTimeout)
|
shutdownTimer := time.After(config.ShutdownTimeout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user