jboss-cli : How do I read one specific system property using jboss-cli?
Asked Answered
H

6

5

I'm new to jboss-cli and working through the 'jboss-cli recipes'.

Question

How do I read one specific property using jboss-cli? E.g.

  • jboss.home.dir (e.g. "-Djboss.home.dir=/path/to/my/jboss")
  • Xmx ("-Xmx=4G")

Context

The "CLI Recipes" documentation has this helpful example to get all system properties. However its 'too much infomration'. I want to script reading one specific property.

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

Overview of all system properties in JBoss AS7+ including OS system properties and properties specified on command line using -D, -P or --properties arguments.

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

Thanks in advance

Horselaugh answered 30/3, 2017 at 14:8 Comment(0)
H
0

This link pointed me to the answer: I can use a groovy script to get the values. From what I see the "jboss-cli command line" does not offer this flexibility.

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

Solution

Here's a solution for jboss home.

[For memory you can get results from "/core-service=platform-mbean/type=memory/:read-attribute(name=heap-memory-usage)"

bash

#!/bin/sh
# Note: must set jbbin to 'jboss home /bin'
groovy -cp $jbbin/client/jboss-cli-client.jar readJbossHome.groovy  

Groovy Note: this is 'quick and dirty'.

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()  
Horselaugh answered 30/3, 2017 at 16:11 Comment(0)
G
4

You could do a :

:resolve-expression(expression=${jboss.home.dir})

Greenhorn answered 31/3, 2017 at 17:15 Comment(0)
F
3

You can use the cli like this:

$JBOSS_HOME/bin/jboss-cli.sh -c --command=/system-property=MY_PROPERTY:read-resource

you get an output like this:

$JBOSS_HOME/bin/jboss-cli.sh -c --command=/system-property=MY_PROPERTY:read-resource
{
    "outcome" => "success",
    "result" => {"value" => "4.0"}
}

which you can extract by piping into something like this:

<cli command>  | grep "{\"value\"" | sed "s/.*value\" => \"\([^\"]*\)\".*/\1/"

its a bit ugly, and there are some nasty edge cases if the values were to be something like "value" => "value =" or something hideous. In general this works OK.

Change the sed command to be a bit more specific to fix that.

Farandole answered 5/10, 2020 at 9:32 Comment(0)
M
1

jboss-cli

If you have a cli command like ehsavoie suggested :resolve-expression(expression=${jboss.home.dir}) and want to use the content of the "result" property within jboss-cli you can save it in a variable. You can use backticks (`) to evaluate expressions.

simple expression

[standalone@localhost:9990 /] :resolve-expression(expression=${jboss.home.dir})
{
    "outcome" => "success",
    "result" => "/home/user/wildfly"
}

use in valiable

[standalone@localhost:9990 /] set wildflydirectory=`:resolve-expression(expression=${jboss.home.dir})`
[standalone@localhost:9990 /] echo $wildflydirectory
/home/user/wildfly

PowerShell

If you happen to use the PowerShell you can use a one-liner to extract even deeply nested results with the help of the cli's --output-json option and PowerShell's ConvertFrom-Json cmdlet. In this way the parsing problem from James Roberts's approach with grep and sed are gone.

$value=(Invoke-Expression "./jboss-cli.ps1 -c --command=':resolve-expression(expression=`${jboss.home.dir})' --output-json" | ConvertFrom-Json).result

It is a bit tricky to quote the command and escape the correct PowerShell special characters.

Maybellemayberry answered 10/2, 2022 at 14:16 Comment(0)
H
0

This link pointed me to the answer: I can use a groovy script to get the values. From what I see the "jboss-cli command line" does not offer this flexibility.

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

Solution

Here's a solution for jboss home.

[For memory you can get results from "/core-service=platform-mbean/type=memory/:read-attribute(name=heap-memory-usage)"

bash

#!/bin/sh
# Note: must set jbbin to 'jboss home /bin'
groovy -cp $jbbin/client/jboss-cli-client.jar readJbossHome.groovy  

Groovy Note: this is 'quick and dirty'.

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()  
Horselaugh answered 30/3, 2017 at 16:11 Comment(0)
U
0

You can also do it via Wildfly management rest call.

  • http://localhost:9990/management
  • POST
  • Headers = Content-Type:application/json
  • Body = { "operation":"resolve-expression", "expression":"${jboss.home.dir}" }
Urethrectomy answered 18/8, 2020 at 7:53 Comment(0)
T
0

With newer Teiid DOCs I have found some useful information I thought this might be helpful to share to people coming across a similar usecase

https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/6.3/html/administration_and_configuration_guide/configure_system_properties_using_the_management_cli

Helps Adding, Removing & Reading System Properties with jboss-cli

Trilly answered 15/10, 2021 at 6:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.