hashicorp/nomad · error
unable to create service - %w
Error message
unable to create service - %w
What it means
Returned by serviceInstall when WindowsServiceManager.CreateService fails to register a new Nomad Windows service (the registry showed no existing one). The service could not be created with the supplied binary path and configuration.
Source
Thrown at command/windows_service_install.go:224
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 {
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)
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Run the install from an elevated (Administrator) shell
- If a stale entry exists, `sc.exe delete nomad`, reboot, and retry
- Check the chained %w cause for the exact SCM error code
- Ensure sufficient free disk space and a valid binary path
Example fix
// before PS> nomad windows install unable to create service - Access is denied // after PS (admin)> nomad windows install
Defensive patterns
Strategy: try-catch
Validate before calling
if !isAdmin() {
log.Fatal("creating the Nomad service requires an elevated shell")
}
out, _ := exec.Command("sc.exe", "query", "nomad").CombinedOutput()
log.Printf("service pre-check: %s", out) Try / catch
srvc, err = m.CreateService(winsvc.WINDOWS_SERVICE_NAME, opts.binaryPath, cfg)
if err != nil {
if errors.Is(err, windows.ERROR_SERVICE_EXISTS) {
// fall back to the GetService/Configure update path
}
return fmt.Errorf("unable to create service - %w", err)
} Prevention
- Run installs elevated
- Handle ERROR_SERVICE_EXISTS by updating instead of creating
- Clear marked-for-deletion entries via reboot
- Verify disk space and valid paths before install
When it happens
Trigger: Creating the Windows service 'Nomad' fails: ERROR_ACCESS_DENIED without elevation, service name already exists but the earlier check missed it, or disk full / invalid parameters.
Common situations: Non-elevated install attempt; leftover service entry deleted-but-pending (marked for deletion); security software blocking service creation.
Related errors
- service registration check failed - %w
- unable to check for existing service - %w
- could not get existing service - %w
- unable to stop existing service - %w
- service install failed - %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/2e12df44accb8120.
Report an issue: GitHub.