hashicorp/nomad · error

unable to configure service - %w

Error message

unable to configure service - %w

What it means

Wraps the failure of `srvc.Configure` when the Nomad service already exists and is being updated (start type, display name, description, binary path). The underlying ChangeServiceConfig error is chained with %w.

Source

Thrown at command/windows_service_install.go:212

	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 {
		srvc, err = m.GetService(winsvc.WINDOWS_SERVICE_NAME)
		if err != nil {
			return fmt.Errorf("unable to get existing service - %w", err)
		}
		defer srvc.Close()
		if err := srvc.Configure(winsvc.WindowsServiceConfiguration{
			StartType:      winsvc.StartAutomatic,
			DisplayName:    winsvc.WINDOWS_SERVICE_DISPLAY_NAME,
			Description:    winsvc.WINDOWS_SERVICE_DESCRIPTION,
			BinaryPathName: cmd,
		}); err != nil {
			return fmt.Errorf("unable to configure service - %w", err)
		}
	} else {
		srvc, err = m.CreateService(winsvc.WINDOWS_SERVICE_NAME, opts.binaryPath,
			winsvc.WindowsServiceConfiguration{
				StartType:      winsvc.StartAutomatic,
				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 {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Run the install from an elevated shell
  2. Quote the binary path (opts.binaryPath) if it contains spaces
  3. `sc.exe delete nomad`, reboot, then fresh install instead of update
  4. Verify the chained cause: ERROR_ACCESS_DENIED vs ERROR_INVALID_PARAMETER

Example fix

// before
cmd := fmt.Sprintf("%s agent -config %s", opts.binaryPath, opts.configDir)
// after
cmd := fmt.Sprintf("\"%s\" agent -config \"%s\"", opts.binaryPath, opts.configDir)
Defensive patterns

Strategy: validation

Validate before calling

if strings.ContainsAny(opts.binaryPath, " \t") {
	log.Printf("warning: binary path contains spaces: %q — ensure the SCM command line is quoted", opts.binaryPath)
}
out, _ := exec.Command("sc.exe", "qc", "nomad").CombinedOutput()
log.Printf("current service config: %s", out)

Try / catch

if err := srvc.Configure(cfg); err != nil {
	if errors.Is(err, windows.ERROR_ACCESS_DENIED) { /* elevate and retry */ }
	return fmt.Errorf("unable to configure service - %w", err)
}

Prevention

When it happens

Trigger: Updating the existing Nomad service's configuration via ChangeServiceConfig fails — access denied, invalid binary path (e.g. unquoted path with spaces), or service handle closed.

Common situations: Non-elevated run attempting to change an existing service; opts.binaryPath contains spaces that break the SCM command string; service is marked for deletion.

Related errors


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