hashicorp/nomad · error
unable to stop existing service - %w
Error message
unable to stop existing service - %w
What it means
Wraps the failure of stopping an already-running Nomad Windows service during `windows install`. The command detected a running service and called Windows service manager Stop; the underlying SCM error is preserved via %w. Install aborts so the stale binary/service state is not half-replaced.
Source
Thrown at command/windows_service_install.go:158
nmdSvc, err := m.GetService(winsvc.WINDOWS_SERVICE_NAME)
if err != nil {
return fmt.Errorf("could not get existing service to stop - %w", err)
}
// If the service is running and the reinstall
// option was not set, return an error
running, err := nmdSvc.IsRunning()
if err != nil {
return fmt.Errorf("unable to determine service state - %w", err)
}
if running && !opts.reinstall {
return fmt.Errorf("service is already running. Please run the\ncommand again with -reinstall to stop the service and install.")
}
if running {
c.Ui.Output(" Stopping existing nomad service")
if err := nmdSvc.Stop(); err != nil {
return fmt.Errorf("unable to stop existing service - %w", err)
}
}
}
// Install the nomad binary into the system
if err = c.binaryInstall(opts); err != nil {
return fmt.Errorf("binary install failed - %w", err)
}
c.Ui.Output(fmt.Sprintf(" Nomad binary installed to: %s", opts.binaryPath))
// Create a configuration directory and add
// a basic configuration file if no configuration
// currently exists
if err = c.configInstall(opts); err != nil {
return fmt.Errorf("configuration install failed - %w", err)
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Re-run the command with -reinstall so the flow stops the service itself before installing
- Open an elevated (Administrator) PowerShell/cmd and retry the install
- Run `sc query nomad` / `sc.exe stop nomad` manually, wait for STOPPED state, then install again
- Reboot to clear a service stuck in marked-for-deletion or stop-pending state
Example fix
// before nomad windows install // after nomad windows install -reinstall
Defensive patterns
Strategy: validation
Validate before calling
sc := exec.Command("sc.exe", "query", "nomad"); out, err := sc.Output()
if err == nil && strings.Contains(string(out), "RUNNING") {
fmt.Println("Service running — use -reinstall or stop it first:",
exec.Command("sc.exe", "stop", "nomad").Run())
} Try / catch
if err := nmdSvc.Stop(); err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) && isAccessDenied(exitErr) {
// prompt for elevation and retry
}
return fmt.Errorf("unable to stop existing service - %w", err)
} Prevention
- Always run `nomad windows install` from an elevated shell
- Check `sc query nomad` state before installing
- Use -reinstall when a service is already present
- Reboot to clear marked-for-deletion services
When it happens
Trigger: Running `nomad windows install` while the Nomad service is running and the golang.org/x/sys windows svc manager Stop call fails (access denied, service marked for deletion, SCM timeout).
Common situations: Installing over a service started under a different elevation; prior uninstall left the service in marked-for-deletion state; service hung and did not respond to the stop control within the timeout.
Related errors
- service install failed - %w
- binary install failed - %w
- service registration check failed - %w
- unable to get existing service - %w
- unable to configure service - %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/68f641aca8db653f.
Report an issue: GitHub.