如何通过 CLI 获取 Wildfly 服务器状态?

How to get Wildfly server status via CLI?

我一直在尝试使用 jboss-cli.bat

验证我们的服务器是否已在 Wildfly 中启动

这是我正在使用的命令:

/host=slave-1/server-config=REST-server-one:read-resource(include-runtime=true)

这就是我从命令中得到的

{
    "outcome" => "success",
    "result" => {
        "auto-start" => true,
        "cpu-affinity" => undefined,
        "group" => "wildfly-server-group",
        "name" => "wildfly-server",
        "priority" => undefined,
        "socket-binding-default-interface" => undefined,
        "socket-binding-group" => undefined,
        "socket-binding-port-offset" => 0,
        "status" => "STARTED",
        "update-auto-start-with-server-status" => false,
        "interface" => undefined,
        "jvm" => undefined,
        "path" => undefined,
        "ssl" => undefined,
        "system-property" => undefined
}

是否有命令 return 该响应中的状态值?

我最终使用了这个

BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line = reader.readLine();
            while (line != null) {
                String[] value  = line.split("=>");
                if(value.length > 1){
                    if(value[0].contains("\"status\"")){
                        System.out.println(value[1]);
                    }
                }
                line = reader.readLine();
            }

如果有人能提出更好的方法,我们将不胜感激。

您应该可以使用 read-attribute 操作。

/host=slave-1/server-config=REST-server-one:read-attribute(name=status)