If we are not getting the exit code assigned then default to it being successful

Useful to know what the exit code is if there is an error
This commit is contained in:
Taliesin Sisson 2015-11-01 21:18:48 +00:00
parent 3cb621f890
commit fe8d99fd8a
1 changed files with 5 additions and 9 deletions

View File

@ -40,6 +40,7 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction {
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
cmd := &packer.RemoteCmd{ cmd := &packer.RemoteCmd{
ExitStatus: 0,
Command: s.Command, Command: s.Command,
Stdout: &stdout, Stdout: &stdout,
Stderr: &stderr, Stderr: &stderr,
@ -57,18 +58,13 @@ func (s *StepShutdown) Run(state multistep.StateBag) multistep.StepAction {
// If the command failed to run, notify the user in some way. // If the command failed to run, notify the user in some way.
if cmd.ExitStatus != 0 { if cmd.ExitStatus != 0 {
state.Put("error", fmt.Errorf( state.Put("error", fmt.Errorf(
"Shutdown command has non-zero exit status.\n\nStdout: %s\n\nStderr: %s", "Shutdown command has non-zero exit status.\n\nExitStatus: %d\n\nStdout: %s\n\nStderr: %s",
stdout.String(), stderr.String())) cmd.ExitStatus, stdout.String(), stderr.String()))
return multistep.ActionHalt return multistep.ActionHalt
} }
if stdout.Len() > 0 { log.Printf("Shutdown stdout: %s", stdout.String())
log.Printf("Shutdown stdout: %s", stdout.String()) log.Printf("Shutdown stderr: %s", stderr.String())
}
if stderr.Len() > 0 {
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", s.Timeout) log.Printf("Waiting max %s for shutdown to complete", s.Timeout)