{"record":{"id":"ef8017d3bc62989c","repo":"hashicorp/nomad","slug":"unable-to-configure-service-w","errorCode":null,"errorMessage":"unable to configure service - %w","messagePattern":"unable to configure service - %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":212,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"service registration check failed - %w\", err)\n\t}\n\n\t// If the service already exists, open it and update. Otherwise\n\t// create a new service.\n\tif exists {\n\t\tsrvc, err = m.GetService(winsvc.WINDOWS_SERVICE_NAME)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to get existing service - %w\", err)\n\t\t}\n\t\tdefer srvc.Close()\n\t\tif err := srvc.Configure(winsvc.WindowsServiceConfiguration{\n\t\t\tStartType:      winsvc.StartAutomatic,\n\t\t\tDisplayName:    winsvc.WINDOWS_SERVICE_DISPLAY_NAME,\n\t\t\tDescription:    winsvc.WINDOWS_SERVICE_DESCRIPTION,\n\t\t\tBinaryPathName: cmd,\n\t\t}); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to configure service - %w\", err)\n\t\t}\n\t} else {\n\t\tsrvc, err = m.CreateService(winsvc.WINDOWS_SERVICE_NAME, opts.binaryPath,\n\t\t\twinsvc.WindowsServiceConfiguration{\n\t\t\t\tStartType:      winsvc.StartAutomatic,\n\t\t\t\tDisplayName:    winsvc.WINDOWS_SERVICE_DISPLAY_NAME,\n\t\t\t\tDescription:    winsvc.WINDOWS_SERVICE_DESCRIPTION,\n\t\t\t\tBinaryPathName: cmd,\n\t\t\t},\n\t\t)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to create service - %w\", err)\n\t\t}\n\t\tdefer srvc.Close()\n\t}\n\n\t// Enable the service in the Windows eventlog\n\tif err := srvc.EnableEventlog(); err != nil {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L194-L230","documentation":"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.","triggerScenarios":"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.","commonSituations":"Non-elevated run attempting to change an existing service; opts.binaryPath contains spaces that break the SCM command string; service is marked for deletion.","solutions":["Run the install from an elevated shell","Quote the binary path (opts.binaryPath) if it contains spaces","`sc.exe delete nomad`, reboot, then fresh install instead of update","Verify the chained cause: ERROR_ACCESS_DENIED vs ERROR_INVALID_PARAMETER"],"exampleFix":"// before\ncmd := fmt.Sprintf(\"%s agent -config %s\", opts.binaryPath, opts.configDir)\n// after\ncmd := fmt.Sprintf(\"\\\"%s\\\" agent -config \\\"%s\\\"\", opts.binaryPath, opts.configDir)","handlingStrategy":"validation","validationCode":"if strings.ContainsAny(opts.binaryPath, \" \\t\") {\n\tlog.Printf(\"warning: binary path contains spaces: %q — ensure the SCM command line is quoted\", opts.binaryPath)\n}\nout, _ := exec.Command(\"sc.exe\", \"qc\", \"nomad\").CombinedOutput()\nlog.Printf(\"current service config: %s\", out)","typeGuard":null,"tryCatchPattern":"if err := srvc.Configure(cfg); err != nil {\n\tif errors.Is(err, windows.ERROR_ACCESS_DENIED) { /* elevate and retry */ }\n\treturn fmt.Errorf(\"unable to configure service - %w\", err)\n}","preventionTips":["Quote binary paths containing spaces in the SCM command string","Run the update path from an elevated shell","Delete + recreate the service if updates keep failing","Validate the binary path exists before Configure"],"tags":["windows","service-control-manager","configuration"],"backgroundTag":"windows-service-configure-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}