diff --git a/provisioner/windows-restart/provisioner.go b/provisioner/windows-restart/provisioner.go index ecf15e6a1..298e20802 100644 --- a/provisioner/windows-restart/provisioner.go +++ b/provisioner/windows-restart/provisioner.go @@ -17,11 +17,11 @@ import ( "github.com/masterzen/winrm" ) -var DefaultRestartCommand = "shutdown /r /f /t 0 /c \"packer restart\"" +var DefaultRestartCommand = `shutdown /r /f /t 0 /c "packer restart"` var DefaultRestartCheckCommand = winrm.Powershell(`echo "${env:COMPUTERNAME} restarted."`) var retryableSleep = 5 * time.Second -var TryCheckReboot = "shutdown.exe -f -r -t 60" -var AbortReboot = "shutdown.exe -a" +var TryCheckReboot = `shutdown /r /f /t 60 /c "packer restart test"` +var AbortReboot = `shutdown /a` type Config struct { common.PackerConfig `mapstructure:",squash"` @@ -124,21 +124,29 @@ var waitForRestart = func(p *Provisioner, comm packer.Communicator) error { for { log.Printf("Check if machine is rebooting...") cmd = &packer.RemoteCmd{Command: trycommand} - err = cmd.StartWithUi(comm, ui) - if err != nil { + if err := p.comm.Start(cmd); err != nil { // Couldn't execute, we assume machine is rebooting already break } - - if cmd.ExitStatus == 1115 || cmd.ExitStatus == 1190 { + cmd.Wait() + if cmd.ExitStatus == 1 { + // SSH provisioner, and we're already rebooting. SSH can reconnect + // without our help; exit this wait loop. + break + } + if cmd.ExitStatus == 1115 || cmd.ExitStatus == 1190 || cmd.ExitStatus == 1717 { // Reboot already in progress but not completed log.Printf("Reboot already in progress, waiting...") time.Sleep(10 * time.Second) + break } if cmd.ExitStatus == 0 { // Cancel reboot we created to test if machine was already rebooting cmd = &packer.RemoteCmd{Command: abortcommand} - cmd.StartWithUi(comm, ui) + if err := p.comm.Start(cmd); err != nil { + return err + } + cmd.Wait() break } } @@ -175,7 +183,6 @@ WaitLoop: return fmt.Errorf("Interrupt detected, quitting waiting for machine to restart") } } - return nil }