hashicorp/nomad · error

unable to stop service - %w

Error message

unable to stop service - %w

What it means

performUninstall wraps the error from srvc.Stop(), which stops the running Nomad service before deleting it. The service could not be transitioned to the stopped state, so uninstall aborts to avoid deleting a running service. The wrapped error carries the SCM failure reason.

Source

Thrown at command/windows_service_uninstall.go:107

	// Check that the nomad service is currently registered
	exists, err := m.IsServiceRegistered(winsvc.WINDOWS_SERVICE_NAME)
	if err != nil {
		return fmt.Errorf("unable to check for existing service - %w", err)
	}

	if !exists {
		return nil
	}

	// Grab the service and ensure the service is stopped
	srvc, err := m.GetService(winsvc.WINDOWS_SERVICE_NAME)
	if err != nil {
		return fmt.Errorf("could not get existing service - %w", err)
	}
	defer srvc.Close()

	if err := srvc.Stop(); err != nil {
		return fmt.Errorf("unable to stop service - %w", err)
	}

	// Remove the service from the event log
	if err := srvc.DisableEventlog(); err != nil {
		return fmt.Errorf("could not remove eventlog configuration - %w", err)
	}

	// Finally, delete the service
	if err := srvc.Delete(); err != nil {
		return fmt.Errorf("could not delete service - %w", err)
	}

	return nil
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Check the wrapped error; wait for in-progress shutdown to finish and retry
  2. Kill the nomad process if it is hung (taskkill) and re-run the uninstall
  3. Run elevated so SERVICE_STOP access is granted
  4. Stop dependent services first, or reboot if the service cannot be stopped

Example fix

// before
sc stop nomad   # hangs, service stuck in STOP_PENDING
// after
taskkill /F /IM nomad.exe
nomad windows service uninstall
Defensive patterns

Strategy: retry

Try / catch

for i := 0; i < 3; i++ {
    if err := uninstallCmd.Run(); err == nil { break }
    time.Sleep(5 * time.Second) // allow STOP_PENDING to resolve
}

Prevention

When it happens

Trigger: srvc.Stop() fails because the service is already stopping but hung, Stop depends on other running services that fail, a timeout elapses waiting for the stop, or access is denied while performUninstall runs.

Common situations: Nomad service hung and unresponsive to stop requests; dependent services blocking the stop; non-elevated uninstall lacking SERVICE_STOP rights.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/2ebf4a0a35b5139e. Report an issue: GitHub.