Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JBoss AS 7 update system property via cli

I can read system properties via the CLI interface by

/system-property=propertyname:read-attribute(name="value")

Is there a simple way I can update the property via the CLI interface?

like image 436
bertolami Avatar asked Mar 22 '12 09:03

bertolami


People also ask

How do I run a CLI script in Jboss?

Launch the Management CLI. You can launch the management CLI by running the jboss-cli script provided with JBoss EAP. For Windows Server, use the EAP_HOME\bin\jboss-cli. bat script to launch the management CLI.

Where is Jboss-CLI XML?

Certain aspects of the management CLI can be customized in its configuration file, jboss-cli. xml . This file must be located either in the EAP_HOME/bin directory or in a custom directory specified with the jboss.


3 Answers

You can use the write-attribute operation to change system property values.

/system-property=propertyname:write-attribute(name="value", value="newValue")

See the answer below for a better description.

like image 101
James R. Perkins Avatar answered Sep 21 '22 13:09

James R. Perkins


You can use the write-attribute operation.

A healthy workflow for the Management CLI is to expose, read and write resource attributes. To give an example of this workflow, we are going to doing the following steps on a fresh default installation of JBoss Application Server 7.1.0Beta1.

Steps to identify and write a system resource attribute

  1. Read all system properties
  2. Read a specific system property in more detail
  3. Expose an example system property attribute
  4. Write an example system property attribute
  5. Expose the change to confirm it
  6. Reset the attribute back to the original value

1. Read all system properties

We don't always know the exact name of what we are looking for. We can use a mix of tab completion and wildcard searches to make it easy to expose the resources and attributes. The read-resource operation is a great start to any workflow, as it exposes all present entities.

[domain@localhost:9999 /] /system-property=*:read-resource
{
    "outcome" => "success",
    "result" => [{
        "address" => [("system-property" => "java.net.preferIPv4Stack")],
        "outcome" => "success",
        "result" => {
            "boot-time" => true,
            "value" => "true"
        }
    }]
}

2. Read a specific system property in more detail

The read-resource operation has exposed the java.net.preferIPv4Stack property. We can query this further by using the read-resource-description operation.

[domain@localhost:9999 /] /system-property=java.net.preferIPv4Stack:read-resource-description 
{
    "outcome" => "success",
    "result" => {
        "description" => "A system property to set on all servers in the domain.",
        "head-comment-allowed" => true,
        "tail-comment-allowed" => false,
        "attributes" => {
            "value" => {
                "type" => STRING,
                "description" => "The value of the system property.",
                "required" => false,
                "access-type" => "read-write",
                "storage" => "configuration",
                "restart-required" => "no-services"
            },
            "boot-time" => {
                "type" => BOOLEAN,
                "description" => "If true the system property is passed on the command-line to the started server jvm. If false, it will be pushed to the server as part of the startup sequence.",
                "required" => false,
                "default" => true,
                "access-type" => "read-write",
                "storage" => "configuration",
                "restart-required" => "no-services"
            }
        }
    }
}

3. Expose an example system property attribute

The read-resource-description operation prints information about the resource, including its attributes. We can specifically query these attributes with the read-attribute operation. Again, tab completion makes it easy to compose these operation strings as you begin typing, and hit tab to complete the string or to suggest available additions.

[domain@localhost:9999 /] /system-property=java.net.preferIPv4Stack:read-attribute(name=boot-time)
{ "outcome" => "success", "result" => true }

4. Write an example system property attribute

In the same way that we just queried the attribute, we can change it. In this case, we can use the write-attribute operation, keeping in mind the intended value type as reported by the read-resource-description operation. This operation declared the attributed to be BOOLEAN, but you should be able to work this out simply by looking at the existing value in the read-attribute command (where it is defined).

[domain@localhost:9999 /] /system-property=java.net.preferIPv4Stack:write-attribute(name=boot-time, value=false)
{
    "outcome" => "success",
    "result" => {
        "domain-results" => {"step-1" => undefined},
        "server-operations" => undefined
    }
}

5. Expose the change to confirm it

We can run the read-attribute operation again to show the value change.

[domain@localhost:9999 /] /system-property=java.net.preferIPv4Stack:read-attribute(name=boot-time)              
{
    "outcome" => "success",
    "result" => false
}

6. Reset the attribute back to the original value

Just to gracefully end the example, let's change the value back to the original state.

[domain@localhost:9999 /] /system-property=java.net.preferIPv4Stack:write-attribute(name=boot-time, value=true) 
{
    "outcome" => "success",
    "result" => {
        "domain-results" => {"step-1" => undefined},
        "server-operations" => undefined
    }
}

Summary

Yes, you can write attribute values. To make the process easier, a workflow habit of exposing the attribute values and file type definitions is a good practice, and should make the process clearer.

like image 32
ddri Avatar answered Sep 17 '22 13:09

ddri


And for completeness, here's how to remove (undefine) a property attribute:

/system-property=propertyname:undefine-attribute(name=attribute-name)
like image 22
mrts Avatar answered Sep 17 '22 13:09

mrts