jboss-cli :如何使用 jboss-cli 读取一个特定的系统属性?

use*_*465 5 jboss wildfly jboss-cli

我是 jboss-cli 的新手,正在研究“jboss-cli 食谱”。

问题

如何使用 jboss-cli读取一个特定属性?例如

  • jboss.home.dir(例如“-Djboss.home.dir=/path/to/my/jboss”)
  • Xmx("-Xmx=4G")

语境

“CLI Recipes”文档有一个有用的示例来获取所有系统属性。然而它的“信息太多”。我想编写读取一个特定属性的脚本。

https://docs.jboss.org/author/display/WFLY10/CLI+Recipes#CLIRecipes-

JBoss AS7+ 中所有系统属性的概述,包括操作系统系统属性和使用 -D、-P 或 --properties 参数在命令行上指定的属性。

Standalone
[standalone@IP_ADDRESS:9999 /] /core-service=platform-mbean/type=runtime:read-attribute(name=system-properties)
Run Code Online (Sandbox Code Playgroud)

提前致谢

use*_*465 0

此链接向我指出了答案:我可以使用常规脚本来获取值。据我所知,“jboss-cli 命令行”不提供这种灵活性。

https://developer.jboss.org/wiki/AdvancedCLIScriptingWithGroovyRhinoJythonEtc

解决方案

这是jboss home的解决方案。

[对于内存,您可以从“/core-service=platform-mbean/type=memory/:read-attribute(name=heap-memory-usage)”获取结果

巴什

#!/bin/sh
# Note: must set jbbin to 'jboss home /bin'
groovy -cp $jbbin/client/jboss-cli-client.jar readJbossHome.groovy  
Run Code Online (Sandbox Code Playgroud)

Groovy 注意:这是“快速而肮脏”的。

import org.jboss.as.cli.scriptsupport.*  

cli = CLI.newInstance()  
cli.connect()  

// Define properties
myParentProp="system-properties"
myProp="jboss.home.dir"

// Retrieve and pluck values
result = cli.cmd("/core-service=platform-mbean/type=runtime:read-resource(recursive=true,include-runtime=false)")

myResult = result.getResponse().get("result")
myParentVal = myResult.get(myParentProp)
myVal = myParentVal.get(myProp)

// Print out results
println "Property detail ${myProp}  is ${myVal}"


cli.disconnect()  
Run Code Online (Sandbox Code Playgroud)