{"record":{"id":"9a8da460b28a7ba9","repo":"hashicorp/nomad","slug":"unable-to-check-for-existing-service-w","errorCode":null,"errorMessage":"unable to check for existing service - %w","messagePattern":"unable to check for existing service - %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":136,"sourceCode":"\t}\n\tdefer m.Close()\n\n\tif err := c.performInstall(m, opts); err != nil {\n\t\tc.Ui.Error(fmt.Sprintf(\"Service install failed: %s\", err))\n\t\treturn 1\n\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","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L118-L154","documentation":"Windows service install error in performInstall: m.IsServiceRegistered(WINDOWS_SERVICE_NAME) failed, so the installer cannot tell whether the Nomad service already exists; it aborts before touching the service.","triggerScenarios":"Thrown at command/windows_service_install.go:136 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run the command from an elevated (Administrator) prompt","Verify the Windows Service Control Manager is healthy","Check the wrapped OS error for specific SCM access problems"],"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"}