{"record":{"id":"e927d61e4eb2fee3","repo":"elastic/elasticsearch","slug":"ret","errorCode":"ret","errorMessage":"Failed ${action} '${serviceId}' service","messagePattern":"Failed (.+?) '(.+?)' service","errorType":"error_code","errorClass":"UserException","httpStatus":null,"severity":"error","filePath":"distribution/tools/windows-service-cli/src/main/java/org/elasticsearch/windows/service/ProcrunCommand.java","lineNumber":84,"sourceCode":"        }\n        String serviceId = getServiceId(options, processInfo.envVars());\n        preExecute(terminal, processInfo, serviceId);\n\n        List<String> procrunCmd = new ArrayList<>();\n        procrunCmd.add(quote(procrun.toString()));\n        procrunCmd.add(\"//%s/%s\".formatted(cmd, serviceId));\n        if (includeLogArgs()) {\n            procrunCmd.add(getLogArgs(serviceId, processInfo.workingDir(), processInfo.envVars()));\n        }\n        procrunCmd.add(getAdditionalArgs(serviceId, processInfo));\n\n        ProcessBuilder processBuilder = new ProcessBuilder(\"cmd.exe\", \"/C\", String.join(\" \", procrunCmd).trim());\n        logger.debug((Supplier<?>) () -> \"Running procrun: \" + String.join(\" \", processBuilder.command()));\n        processBuilder.inheritIO();\n        Process process = startProcess(processBuilder);\n        int ret = process.waitFor();\n        if (ret != ExitCodes.OK) {\n            throw new UserException(ret, getFailureMessage(serviceId));\n        } else {\n            terminal.println(getSuccessMessage(serviceId));\n        }\n    }\n\n    /** Quotes the given String. */\n    static String quote(String s) {\n        return '\"' + s + '\"';\n    }\n\n    /** Determines the service id for the Elasticsearch service that should be used */\n    private static String getServiceId(OptionSet options, Map<String, String> env) throws UserException {\n        List<?> args = options.nonOptionArguments();\n        if (args.size() > 1) {\n            throw new UserException(ExitCodes.USAGE, \"too many arguments, expected one service id\");\n        }\n        final String serviceId;\n        if (args.size() > 0) {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/distribution/tools/windows-service-cli/src/main/java/org/elasticsearch/windows/service/ProcrunCommand.java#L66-L102","documentation":"Thrown by ProcrunCommand.execute when the underlying procrun executable returns a non-zero exit code. The UserException carries that exit code (`ret`) so the CLI exits with the same value procrun used. The message is templated by getFailureMessage(serviceId) and typically says something like `Failed installing service 'elasticsearch-service-x64'`. This is a passthrough of procrun's own failure, not a Java-level error.","triggerScenarios":"Installing a service that already exists. Removing or stopping a service that is not installed/running. Running without the Administrator privileges procrun requires for service operations. Supplying a service id that collides with an existing service.","commonSituations":"Re-running `install` after a previous failed uninstall left the service registered. Non-admin shell. Service name conflicts with another product.","solutions":["Run the command from an Administrator shell.","For install failures, check if the service already exists: `sc query <serviceId>` and remove it first with the `remove` subcommand.","Read the procrun log files (default in logs/) for the underlying Windows error code.","Confirm the service id matches across install/manage/remove invocations."],"exampleFix":"REM before (service already registered)\nbin\\elasticsearch-service.bat install\nREM after\nbin\\elasticsearch-service.bat remove\nbin\\elasticsearch-service.bat install","handlingStrategy":"try-catch","validationCode":"// Before invoking, check whether the service is in the expected state for the action:\n// e.g. for 'install', assert the service is absent:\nProcess p = new ProcessBuilder(\"sc\", \"query\", serviceId).redirectErrorStream(true).start();\nif (p.waitFor() == 0) {\n    throw new IllegalStateException(\"Service \" + serviceId + \" already exists; remove it first.\");\n}","typeGuard":"static boolean serviceIsRegistered(String serviceId) throws IOException, InterruptedException {\n    Process p = new ProcessBuilder(\"sc\", \"query\", serviceId).start();\n    return p.waitFor() == 0;\n}","tryCatchPattern":"try {\n    procrunCmd.execute(...);\n} catch (UserException e) {\n    // e.exitCode mirrors procrun's exit code; surface the procrun logs/\n    log.error(\"procrun {} failed for service {} (exit {}); see logs/\", cmd, serviceId, e.exitCode, e);\n    throw e;\n}","preventionTips":["Run service install/remove/start/stop from an elevated (Administrator) shell.","Always pair install/remove with a specific service id; avoid re-installing over an existing registration.","Capture procrun log output (logs/) for post-mortem."],"tags":["windows","service","procrun","cli","permissions"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}