hashicorp/nomad · error

service install failed - %w

Error message

service install failed - %w

What it means

Top-level wrapper for the whole `serviceInstall` step of `windows install`: it registers or updates the Nomad Windows service. All SCM failures inside serviceInstall (registration check, create, configure, eventlog, start/stop) are surfaced here with %w.

Source

Thrown at command/windows_service_install.go:182

	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)
	}

	c.Ui.Output(fmt.Sprintf("  Nomad configuration directory: %s", opts.configDir))
	c.Ui.Output(fmt.Sprintf("  Nomad agent data directory: %s", opts.configDir))

	// Now let's install that service
	if err := c.serviceInstall(m, opts); err != nil {
		return fmt.Errorf("service install failed - %w", err)
	}

	return nil
}

func (c *WindowsServiceInstallCommand) serviceInstall(m winsvc.WindowsServiceManager, opts *windowsInstallOpts) error {
	var err error
	var srvc winsvc.WindowsService
	cmd := fmt.Sprintf("%s agent -config %s", opts.binaryPath, opts.configDir)

	exists, err := m.IsServiceRegistered(winsvc.WINDOWS_SERVICE_NAME)
	if err != nil {
		return fmt.Errorf("service registration check failed - %w", err)
	}

	// If the service already exists, open it and update. Otherwise
	// create a new service.
	if exists {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Read the chained %w cause to identify the exact SCM operation that failed
  2. Re-run from an elevated shell — most causes are ERROR_ACCESS_DENIED
  3. Run `sc.exe delete nomad` for a stale service, reboot, then install again
  4. Verify no service named 'Nomad' already exists with `sc query nomad`

Example fix

// before
C:\> nomad windows install
service install failed - unable to create service - Access is denied
// after (elevated shell)
C:\> nomad windows install
Defensive patterns

Strategy: try-catch

Validate before calling

if !isAdmin() {
	log.Fatal("windows install requires an elevated (Administrator) shell")
}
out, _ := exec.Command("sc.exe", "query", "nomad").Output()
log.Printf("pre-install service state: %s", out)

Try / catch

if err := c.serviceInstall(m, opts); err != nil {
	log.Printf("service install failed: %v", err) // unwrap %w chain to find SCM step
	if errors.Is(err, windows.ERROR_ACCESS_DENIED) { /* elevate and retry */ }
	return fmt.Errorf("service install failed - %w", err)
}

Prevention

When it happens

Trigger: Any sub-step of serviceInstall returns an error: IsServiceRegistered, GetService, Configure, CreateService, EnableEventlog, Stop, or Start on the Nomad service.

Common situations: Installing without administrator rights (SCM access denied); service name collision with a pre-existing non-Nomad service; SCM corruption after an incomplete uninstall.

Related errors


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