hashicorp/nomad · error
unable to get existing service - %w
Error message
unable to get existing service - %w
What it means
Returned by serviceInstall when GetService fails to open the existing Nomad Windows service for update. Registration was detected, but the service handle needed to reconfigure it could not be fetched.
Source
Thrown at command/windows_service_install.go:203
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 {
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,
},View on GitHub (pinned to 482b49bf1a)
Solutions
- Re-run from an elevated shell
- Run `sc.exe delete nomad`, reboot, then re-run install to take the CreateService path
- Check the chained %w cause for the concrete SCM error code
- Avoid concurrent installs/uninstalls of the Nomad service
Example fix
// before nomad windows install // after sc.exe delete nomad && nomad windows install
Defensive patterns
Strategy: retry
Validate before calling
out, _ := exec.Command("sc.exe", "query", "nomad").CombinedOutput()
if strings.Contains(string(out), "STOP_PENDING") || strings.Contains(string(out), "DELETING") {
log.Println("service in transitional state; wait or reboot before installing")
} Try / catch
srvc, err = m.GetService(winsvc.WINDOWS_SERVICE_NAME)
if err != nil {
if errors.Is(err, windows.ERROR_SERVICE_MARKED_FOR_DELETE) {
// wait for deletion to settle, then retry once
}
return fmt.Errorf("unable to get existing service - %w", err)
} Prevention
- Don't uninstall and install the service concurrently
- Reboot after `sc delete` if the service was running
- Run elevated so the service handle opens with sufficient rights
When it happens
Trigger: Service is registered but OpenService fails: insufficient rights, service registered under a name resolved differently, or the service handle cannot be opened due to SCM state.
Common situations: Race where the service was deleted between the existence check and open; running without elevation; corrupted service entry left by a failed prior install/uninstall.
Related errors
- unable to stop existing service - %w
- service install failed - %w
- service registration check failed - %w
- unable to configure service - %w
- unable to create service - %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/fcaecc09b679d3a1.
Report an issue: GitHub.