{"record":{"id":"e894c3ce3ab93a88","repo":"hashicorp/nomad","slug":"could-not-get-existing-service-to-stop-w","errorCode":null,"errorMessage":"could not get existing service to stop - %w","messagePattern":"could not get existing service to stop - %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":142,"sourceCode":"\t}\n\n\tc.Ui.Info(\"Successfully installed nomad Windows service\")\n\treturn 0\n}\n\nfunc (c *WindowsServiceInstallCommand) performInstall(m winsvc.WindowsServiceManager, opts *windowsInstallOpts) error {\n\t// Check if the nomad service has already been\n\t// registered. If so the service needs to be\n\t// stopped before proceeding with the install.\n\texists, err := m.IsServiceRegistered(winsvc.WINDOWS_SERVICE_NAME)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to check for existing service - %w\", err)\n\t}\n\n\tif exists {\n\t\tnmdSvc, err := m.GetService(winsvc.WINDOWS_SERVICE_NAME)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not get existing service to stop - %w\", err)\n\t\t}\n\n\t\t// If the service is running and the reinstall\n\t\t// option was not set, return an error\n\t\trunning, err := nmdSvc.IsRunning()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to determine service state - %w\", err)\n\t\t}\n\t\tif running && !opts.reinstall {\n\t\t\treturn fmt.Errorf(\"service is already running. Please run the\\ncommand again with -reinstall to stop the service and install.\")\n\t\t}\n\n\t\tif running {\n\t\t\tc.Ui.Output(\"  Stopping existing nomad service\")\n\t\t\tif err := nmdSvc.Stop(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"unable to stop existing service - %w\", err)\n\t\t\t}\n\t\t}","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L124-L160","documentation":"Returned by performInstall when WindowsServiceManager.GetService fails to open the already-registered Nomad service prior to stopping it for reinstall. The service exists but its handle could not be obtained.","triggerScenarios":"Thrown at command/windows_service_install.go:142 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-run from an elevated prompt with sufficient SCM rights","Check the service wasn't deleted concurrently","Inspect the wrapped OS error for access-denied details"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}