Merge pull request #6606 from hashicorp/fix_6301
Make Windows-Restart provisioner work even when using ssh communicator
This commit is contained in:
commit
af48214ddd
|
@ -17,11 +17,11 @@ import (
|
||||||
"github.com/masterzen/winrm"
|
"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 DefaultRestartCheckCommand = winrm.Powershell(`echo "${env:COMPUTERNAME} restarted."`)
|
||||||
var retryableSleep = 5 * time.Second
|
var retryableSleep = 5 * time.Second
|
||||||
var TryCheckReboot = "shutdown.exe -f -r -t 60"
|
var TryCheckReboot = `shutdown /r /f /t 60 /c "packer restart test"`
|
||||||
var AbortReboot = "shutdown.exe -a"
|
var AbortReboot = `shutdown /a`
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
common.PackerConfig `mapstructure:",squash"`
|
common.PackerConfig `mapstructure:",squash"`
|
||||||
|
@ -124,21 +124,29 @@ var waitForRestart = func(p *Provisioner, comm packer.Communicator) error {
|
||||||
for {
|
for {
|
||||||
log.Printf("Check if machine is rebooting...")
|
log.Printf("Check if machine is rebooting...")
|
||||||
cmd = &packer.RemoteCmd{Command: trycommand}
|
cmd = &packer.RemoteCmd{Command: trycommand}
|
||||||
err = cmd.StartWithUi(comm, ui)
|
if err := p.comm.Start(cmd); err != nil {
|
||||||
if err != nil {
|
|
||||||
// Couldn't execute, we assume machine is rebooting already
|
// Couldn't execute, we assume machine is rebooting already
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
cmd.Wait()
|
||||||
if cmd.ExitStatus == 1115 || cmd.ExitStatus == 1190 {
|
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
|
// Reboot already in progress but not completed
|
||||||
log.Printf("Reboot already in progress, waiting...")
|
log.Printf("Reboot already in progress, waiting...")
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if cmd.ExitStatus == 0 {
|
if cmd.ExitStatus == 0 {
|
||||||
// Cancel reboot we created to test if machine was already rebooting
|
// Cancel reboot we created to test if machine was already rebooting
|
||||||
cmd = &packer.RemoteCmd{Command: abortcommand}
|
cmd = &packer.RemoteCmd{Command: abortcommand}
|
||||||
cmd.StartWithUi(comm, ui)
|
if err := p.comm.Start(cmd); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd.Wait()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,7 +183,6 @@ WaitLoop:
|
||||||
return fmt.Errorf("Interrupt detected, quitting waiting for machine to restart")
|
return fmt.Errorf("Interrupt detected, quitting waiting for machine to restart")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue