{"record":{"id":"57157b941b5e7c8c","repo":"hashicorp/nomad","slug":"service-install-failed-w","errorCode":null,"errorMessage":"service install failed - %w","messagePattern":"service install failed - %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":182,"sourceCode":"\tif err = c.binaryInstall(opts); err != nil {\n\t\treturn fmt.Errorf(\"binary install failed - %w\", err)\n\t}\n\n\tc.Ui.Output(fmt.Sprintf(\"  Nomad binary installed to: %s\", opts.binaryPath))\n\n\t// Create a configuration directory and add\n\t// a basic configuration file if no configuration\n\t// currently exists\n\tif err = c.configInstall(opts); err != nil {\n\t\treturn fmt.Errorf(\"configuration install failed - %w\", err)\n\t}\n\n\tc.Ui.Output(fmt.Sprintf(\"  Nomad configuration directory: %s\", opts.configDir))\n\tc.Ui.Output(fmt.Sprintf(\"  Nomad agent data directory: %s\", opts.configDir))\n\n\t// Now let's install that service\n\tif err := c.serviceInstall(m, opts); err != nil {\n\t\treturn fmt.Errorf(\"service install failed - %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (c *WindowsServiceInstallCommand) serviceInstall(m winsvc.WindowsServiceManager, opts *windowsInstallOpts) error {\n\tvar err error\n\tvar srvc winsvc.WindowsService\n\tcmd := fmt.Sprintf(\"%s agent -config %s\", opts.binaryPath, opts.configDir)\n\n\texists, err := m.IsServiceRegistered(winsvc.WINDOWS_SERVICE_NAME)\n\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 {","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L164-L200","documentation":"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.","triggerScenarios":"Any sub-step of serviceInstall returns an error: IsServiceRegistered, GetService, Configure, CreateService, EnableEventlog, Stop, or Start on the Nomad service.","commonSituations":"Installing without administrator rights (SCM access denied); service name collision with a pre-existing non-Nomad service; SCM corruption after an incomplete uninstall.","solutions":["Read the chained %w cause to identify the exact SCM operation that failed","Re-run from an elevated shell — most causes are ERROR_ACCESS_DENIED","Run `sc.exe delete nomad` for a stale service, reboot, then install again","Verify no service named 'Nomad' already exists with `sc query nomad`"],"exampleFix":"// before\nC:\\> nomad windows install\nservice install failed - unable to create service - Access is denied\n// after (elevated shell)\nC:\\> nomad windows install","handlingStrategy":"try-catch","validationCode":"if !isAdmin() {\n\tlog.Fatal(\"windows install requires an elevated (Administrator) shell\")\n}\nout, _ := exec.Command(\"sc.exe\", \"query\", \"nomad\").Output()\nlog.Printf(\"pre-install service state: %s\", out)","typeGuard":null,"tryCatchPattern":"if err := c.serviceInstall(m, opts); err != nil {\n\tlog.Printf(\"service install failed: %v\", err) // unwrap %w chain to find SCM step\n\tif errors.Is(err, windows.ERROR_ACCESS_DENIED) { /* elevate and retry */ }\n\treturn fmt.Errorf(\"service install failed - %w\", err)\n}","preventionTips":["Run the install elevated every time","Inspect the full wrapped error chain for the failing SCM step","Delete stale services (`sc.exe delete nomad`) before reinstalling","Avoid running parallel installs/uninstalls"],"tags":["windows","service-control-manager","installation"],"backgroundTag":"windows-service-registration-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"}