{"record":{"id":"39a6754e24df9d9a","repo":"hashicorp/packer","slug":"restart-script-exited-with-non-zero-exit-status","errorCode":null,"errorMessage":"Restart script exited with non-zero exit status: %d","messagePattern":"Restart script exited with non-zero exit status: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/windows-restart/provisioner.go","lineNumber":128,"sourceCode":"\tp.cancelLock.Unlock()\n\n\tui.Say(\"Restarting Machine\")\n\tp.comm = comm\n\tp.ui = ui\n\n\tvar cmd *packersdk.RemoteCmd\n\tcommand := p.config.RestartCommand\n\terr := retry.Config{StartTimeout: p.config.RestartTimeout}.Run(ctx, func(context.Context) error {\n\t\tcmd = &packersdk.RemoteCmd{Command: command}\n\t\treturn cmd.RunWithUi(ctx, comm, ui)\n\t})\n\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif cmd.ExitStatus() != 0 && cmd.ExitStatus() != 1115 && cmd.ExitStatus() != 1190 {\n\t\treturn fmt.Errorf(\"Restart script exited with non-zero exit status: %d\", cmd.ExitStatus())\n\t}\n\n\treturn waitForRestart(ctx, p, comm)\n}\n\nvar waitForRestart = func(ctx context.Context, p *Provisioner, comm packersdk.Communicator) error {\n\tui := p.ui\n\tui.Say(\"Waiting for machine to restart...\")\n\twaitDone := make(chan bool, 1)\n\ttimeout := time.After(p.config.RestartTimeout)\n\tvar err error\n\n\tp.comm = comm\n\tvar cmd *packersdk.RemoteCmd\n\ttrycommand := TryCheckReboot\n\tabortcommand := AbortReboot\n\n\t// Stolen from Vagrant reboot checker","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/windows-restart/provisioner.go#L110-L146","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nprovisioner \"windows-restart\" {\n  restart_command = [\"powershell\", \"-command\", \"Restart-Computer\"]\n}\n// after\nprovisioner \"windows-restart\" {\n  restart_command = [\"powershell\", \"-command\", \"Restart-Computer -Force; if ($LASTEXITCODE -eq 3010) { exit 0 } else { exit $LASTEXITCODE }\"]\n}","handlingStrategy":"validation","validationCode":"# Test the restart command manually on the guest before encoding it:\npowershell -command \"Restart-Computer -Force; exit $LASTEXITCODE\"  # confirm exit codes 0/1115/1190","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["provisioner","windows-restart","exit-code","windows"],"backgroundTag":"remote-command-nonzero-exit","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}