hashicorp/packer · error
Restart script exited with non-zero exit status: %d
Error message
Restart script exited with non-zero exit status: %d
What it means
The windows-restart provisioner runs the configured restart_command on the Windows guest and validates its exit status. Codes 1115 (ERROR_SHUTDOWN_IN_PROGRESS) and 1190 (ERROR_SHUTDOWN_IS_SCHEDULED) are accepted as successful reboot initiations; any other non-zero status means the restart command itself failed and Provision aborts with this message.
Source
Thrown at provisioner/windows-restart/provisioner.go:128
p.cancelLock.Unlock()
ui.Say("Restarting Machine")
p.comm = comm
p.ui = ui
var cmd *packersdk.RemoteCmd
command := p.config.RestartCommand
err := retry.Config{StartTimeout: p.config.RestartTimeout}.Run(ctx, func(context.Context) error {
cmd = &packersdk.RemoteCmd{Command: command}
return cmd.RunWithUi(ctx, comm, ui)
})
if err != nil {
return err
}
if cmd.ExitStatus() != 0 && cmd.ExitStatus() != 1115 && cmd.ExitStatus() != 1190 {
return fmt.Errorf("Restart script exited with non-zero exit status: %d", cmd.ExitStatus())
}
return waitForRestart(ctx, p, comm)
}
var waitForRestart = func(ctx context.Context, p *Provisioner, comm packersdk.Communicator) error {
ui := p.ui
ui.Say("Waiting for machine to restart...")
waitDone := make(chan bool, 1)
timeout := time.After(p.config.RestartTimeout)
var err error
p.comm = comm
var cmd *packersdk.RemoteCmd
trycommand := TryCheckReboot
abortcommand := AbortReboot
// Stolen from Vagrant reboot checkerView on GitHub (pinned to eb36e3c3e4)
Solutions
- Add the offending exit code to the accepted set by overriding restart_command to wrap the restart and exit 0 on that code (e.g. `...; if ($LASTEXITCODE -eq <code>) { exit 0 }`)
- Verify the WinRM user has shutdown privileges on the guest
- Test restart_command manually on the Windows instance to see the real error
- Ensure no policy/AV software is blocking the shutdown command
Example fix
// before
provisioner "windows-restart" {
restart_command = ["powershell", "-command", "Restart-Computer"]
}
// after
provisioner "windows-restart" {
restart_command = ["powershell", "-command", "Restart-Computer -Force; if ($LASTEXITCODE -eq 3010) { exit 0 } else { exit $LASTEXITCODE }"]
} Defensive patterns
Strategy: validation
Validate before calling
# Test the restart command manually on the guest before encoding it: powershell -command "Restart-Computer -Force; exit $LASTEXITCODE" # confirm exit codes 0/1115/1190
Prevention
- Verify the WinRM user holds SeShutdownPrivilege and admin rights
- Test custom restart_command exit codes on a disposable guest first
- Wrap the restart command to normalize application-specific codes to 0
- Check Group Policy/AV for shutdown blockers before provisioning
When it happens
Trigger: cmd.RunWithUi runs the restart_command (default: a PowerShell shutdown/restart) and it exits non-zero with a code other than 1115/1190 — e.g. access denied, shutdown.exe unavailable, or a custom restart_command that returns its own failure codes.
Common situations: Custom restart_command scripts returning application-specific error codes; insufficient Windows user privileges (SeShutdownPrivilege missing); antivirus or Group Policy blocking shutdown; typos in a custom restart_command.
Related errors
- Timeout waiting for machine to restart.
- Interrupt detected, quitting waiting for machine to restart
- Only one of script or scripts can be specified.
- Either a script file or inline script must be specified.
- failed to open Packer release zip: %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/39a6754e24df9d9a.
Report an issue: GitHub.