hashicorp/nomad · error
could not stop service
Error message
could not stop service - %w
What it means
Wraps the failure of `srvc.Stop` after the service is installed/updated. Install ensures the service is stopped so the next Start picks up the newly installed binary. If the SCM stop control fails, install aborts with this message.
Solutions
- Wait for the service to reach STOPPED (`sc query nomad`), then re-run install
- Force-kill the nomad.exe process (`taskkill /f /im nomad.exe`) if stop-pending, then retry
- Run the command from an elevated shell
- Reboot the host if the service is stuck in a transitional state
Example fix
// before nomad windows install // after taskkill /f /im nomad.exe; nomad windows install
Defensive patterns
Strategy: retry
Validate before calling
out, _ := exec.Command("sc.exe", "query", "nomad").CombinedOutput()
if strings.Contains(string(out), "STOP_PENDING") {
log.Println("service is stopping; wait for STOPPED before installing")
} Try / catch
if err := srvc.Stop(); err != nil {
if errors.Is(err, windows.ERROR_SERVICE_NOT_ACTIVE) {
return nil // already stopped — safe to proceed
}
return fmt.Errorf("could not stop service - %w", err)
} Prevention
- Poll `sc query nomad` until STOPPED before reinstalling
- Treat ERROR_SERVICE_NOT_ACTIVE as success
- Force-kill a hung nomad.exe before reinstalling
- Run elevated so stop controls are accepted
When it happens
Trigger: Sending SERVICE_CONTROL_STOP to the freshly installed/updated Nomad service fails: service not accepting stop controls, stop pending timeout, or access denied on the handle.
Common situations: Service entered a stop-pending state and SCM timed out; the service process hung during early startup; insufficient privileges on the service handle.
Related errors
- could not delete service
- could not get existing service
- service install failed
- service registration check failed
- unable to check for existing service
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/f56defcc59e016dd.
Report an issue: GitHub.
Appendix: source
Thrown at command/windows_service_install.go:236
DisplayName: winsvc.WINDOWS_SERVICE_DISPLAY_NAME,
Description: winsvc.WINDOWS_SERVICE_DESCRIPTION,
BinaryPathName: cmd,
},
)
if err != nil {
return fmt.Errorf("unable to create service - %w", err)
}
defer srvc.Close()
}
// Enable the service in the Windows eventlog
if err := srvc.EnableEventlog(); err != nil {
return fmt.Errorf("could not configure eventlog - %w", err)
}
// Ensure the service is stopped
if err := srvc.Stop(); err != nil {
return fmt.Errorf("could not stop service - %w", err)
}
// Start the service so the new binary is in use
if err := srvc.Start(); err != nil {
return fmt.Errorf("could not start service - %w", err)
}
return nil
}
func (c *WindowsServiceInstallCommand) configInstall(opts *windowsInstallOpts) error {
// If the config or data directory are unset, default them
if opts.configDir == "" {
opts.configDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, "config")
}
if opts.dataDir == "" {
opts.dataDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, "data")
}View on GitHub (pinned to 482b49bf1a)