{"record":{"id":"481b1a3de267dcbe","repo":"hashicorp/nomad","slug":"could-not-start-service-w","errorCode":null,"errorMessage":"could not start service - %w","messagePattern":"could not start service - %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":241,"sourceCode":"\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 {\n\t\treturn fmt.Errorf(\"could not configure eventlog - %w\", err)\n\t}\n\n\t// Ensure the service is stopped\n\tif err := srvc.Stop(); err != nil {\n\t\treturn fmt.Errorf(\"could not stop service - %w\", err)\n\t}\n\n\t// Start the service so the new binary is in use\n\tif err := srvc.Start(); err != nil {\n\t\treturn fmt.Errorf(\"could not start service - %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (c *WindowsServiceInstallCommand) configInstall(opts *windowsInstallOpts) error {\n\t// If the config or data directory are unset, default them\n\tif opts.configDir == \"\" {\n\t\topts.configDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, \"config\")\n\t}\n\tif opts.dataDir == \"\" {\n\t\topts.dataDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, \"data\")\n\t}\n\n\tvar err error\n\tif opts.configDir, err = c.winPaths.Expand(opts.configDir); err != nil {\n\t\treturn fmt.Errorf(\"cannot generate configuration path - %s\", err)\n\t}","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L223-L259","documentation":"During a Nomad Windows service upgrade, performInstall stops the old service, replaces the binary, and then calls srvc.Start() to bring the service back up so the new binary is in use. This error wraps any failure from that start attempt via %w, so the underlying Windows service manager error is preserved. It means the binary was installed but the service could not be relaunched.","triggerScenarios":"Calling 'nomad windows service install' (upgrade path) when srvc.Start() fails after the binary swap — e.g. the service executable path is invalid, the service account lacks permissions, the SCM rejects the start, or the binary is corrupted/locked.","commonSituations":"Upgrading Nomad while a group policy or antivirus blocks the new nomad.exe; the service's configured binary path was changed manually; insufficient privileges of the installing user; Windows service dependencies not running.","solutions":["Read the wrapped %w error to identify the SCM failure reason","Verify the installed nomad.exe exists at the service's binPath and is not blocked by antivirus","Start the service manually with 'net start nomad' or 'sc start nomad' and check Windows Event Viewer for details","Confirm you ran the install from an elevated (Administrator) shell","Check the service's Log On account permissions"],"exampleFix":"// before: opaque failure at service start\nreturn fmt.Errorf(\"could not start service - %w\", err)\n// after: start manually and inspect SCM reason\n// C:\\> sc start nomad\n// C:\\> Get-WinEvent -LogName System -MaxEvents 20 | Where-Object {$_.ProviderName -eq 'Service Control Manager'}","handlingStrategy":"try-catch","validationCode":"// Before install, confirm the service can be started manually\n// PowerShell:\n$s = Get-Service nomad -ErrorAction SilentlyContinue\nif ($s -and $s.Status -eq 'Stopped') { Start-Service nomad; Stop-Service nomad }","typeGuard":null,"tryCatchPattern":"err := srvc.Start()\nif err != nil {\n    return fmt.Errorf(\"could not start service - %w\", err)\n}\n// Caller: inspect errors.Unwrap(err) / *exec.Error to distinguish path vs permission failures","preventionTips":["Always run the installer from an elevated Administrator shell","Test start/stop of the service manually before upgrading","Ensure antivirus does not block newly written nomad.exe","Keep the service binPath pointing at the install directory"],"tags":["windows","service","upgrade"],"backgroundTag":"windows-service-start-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"}