JBoss AS 7 update system property via cli
Asked Answered
L

3

19

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?

Lorant answered 22/3, 2012 at 9:35 Comment(0)
Z
21

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.

Zulema answered 22/3, 2012 at 18:2 Comment(7)
No need for a feature request, as the write-attribute operation can update these attributes as the name suggests.Overleap
Yes, that definitely works. Not sure why it wasn't working when I tried it earlier, but I was probably just using it wrong :-)Zulema
Is it possible to create / overwrite a property? If I add an existent property I get an error and if I write-attribute a non existent property I gent another error.Wellappointed
Hi, How to change multiple attributes at single query. I have tried update-properties commands but which is not working correctly... Can you give me an IDEA?Forzando
You'd have to use the CLI batch command and then execute-batch. There is no way to update multiple properties in a single command.Zulema
is server restart required for reflecting this new value?Cranberry
Depends on how the value is used. If you need it during deployment processing or in say a singleton of some sort, yes.Zulema
O
20

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.

Overleap answered 13/4, 2012 at 2:26 Comment(1)
thanks for your answer, it helps me a lot. Do I need to run another command for the change to take effect? I was able to change the value, but it seems that jboss did not recognize the change.Cranage
I
3

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

/system-property=propertyname:undefine-attribute(name=attribute-name)
Infundibuliform answered 24/11, 2016 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.