JBoss Community Archive (Read Only)

JBoss AS 7.1

CLI Recipes

Properties

Adding, reading and removing system property using CLI

For standalone mode:

$ ./bin/jboss-cli.sh --connect controller=IP_ADDRESS
[standalone@IP_ADDRESS:9999 /] /system-property=foo:add(value=bar)
[standalone@IP_ADDRESS:9999 /] /system-property=foo:read-resource
{
    "outcome" => "success",
    "result" => {"value" => "bar"}
}
[standalone@IP_ADDRESS:9999 /] /system-property=foo:remove
{"outcome" => "success"}

For domain mode the same commands are used, you can add/read/remove system properties for:
All hosts and server instances in domain

[domain@IP_ADDRESS:9999 /] /system-property=foo:add(value=bar)
[domain@IP_ADDRESS:9999 /] /system-property=foo:read-resource
[domain@IP_ADDRESS:9999 /] /system-property=foo:remove

Host and its server instances

[domain@IP_ADDRESS:9999 /] /host=master/system-property=foo:add(value=bar)
[domain@IP_ADDRESS:9999 /] /host=master/system-property=foo:read-resource
[domain@IP_ADDRESS:9999 /] /host=master/system-property=foo:remove

Just one server instance

[domain@IP_ADDRESS:9999 /] /host=master/server-config=server-one/system-property=foo:add(value=bar)
[domain@IP_ADDRESS:9999 /] /host=master/server-config=server-one/system-property=foo:read-resource
[domain@IP_ADDRESS:9999 /] /host=master/server-config=server-one/system-property=foo:remove

Overview of all system properties

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)

Domain

[domain@IP_ADDRESS:9999 /] /host=master/core-service=platform-mbean/type=runtime:read-attribute(name=system-properties)
[domain@IP_ADDRESS:9999 /] /host=master/server=server-one/core-service=platform-mbean/type=runtime:read-attribute(name=system-properties)

Configuration

List Subsystems

[standalone@localhost:9999 /] /:read-children-names(child-type=subsystem)
{
    "outcome" => "success",
    "result" => [
        "configadmin",
        "datasources",
        "deployment-scanner",
        "ee",
        "ejb3",
        "infinispan",
        "jaxrs",
        "jca",
        "jdr",
        "jmx",
        "jpa",
        "logging",
        "mail",
        "naming",
        "osgi",
        "pojo",
        "remoting",
        "resource-adapters",
        "sar",
        "security",
        "threads",
        "transactions",
        "web",
        "webservices",
        "weld"
    ]
}

List description of available attributes and childs

Descriptions, possible attribute type and values, permission and whether expressions ( ${ ... } ) are allowed from the underlying model are shown by the read-resource-description comand.

/subsystem=datasources/data-source=ExampleDS:read-resource-description
{
    "outcome" => "success",
    "result" => {
        "description" => "A JDBC data-source configuration",
        "head-comment-allowed" => true,
        "tail-comment-allowed" => true,
        "attributes" => {
            "connection-url" => {
                "type" => STRING,
                "description" => "The JDBC driver connection URL",
                "expressions-allowed" => true,
                "nillable" => false,
                "min-length" => 1L,
                "max-length" => 2147483647L,
                "access-type" => "read-write",
                "storage" => "configuration",
                "restart-required" => "no-services"
            },
            "driver-class" => {
                "type" => STRING,
                "description" => "The fully qualified name of the JDBC driver class",
                "expressions-allowed" => true,
                "nillable" => true,
                "min-length" => 1L,
                "max-length" => 2147483647L,
                "access-type" => "read-write",
                "storage" => "configuration",
                "restart-required" => "no-services"
            },
            "datasource-class" => {
                "type" => STRING,
                "description" => "The fully qualified name of the JDBC datasource class",
                "expressions-allowed" => true,
                "nillable" => true,
                "min-length" => 1L,
                "max-length" => 2147483647L,
                "access-type" => "read-write",
                "storage" => "configuration",
                "restart-required" => "no-services"
            },
            "jndi-name" => {
                "type" => STRING,
                "description" => "Specifies the JNDI name for the datasource",
                "expressions-allowed" => true,
                "nillable" => false,
                "access-type" => "read-write",
                "storage" => "configuration",
                "restart-required" => "no-services"
            },
           ...

View configuration as XML for domain model or host model

Assume you have a host that is called master

[domain@localhost:9999 /] /host=master:read-config-as-xml

Just for the domain or standalone

[domain@localhost:9999 /] :read-config-as-xml

Take a snapshot of what the current domain is

[domain@localhost:9999 /] :take-snapshot()
{
    "outcome" => "success",
    "result" => {
        "domain-results" => {"step-1" => {"name" => "/home/anil/as7/jboss-as/build/target/jboss-as-7.1.0.Alpha1-SNAPSHOT/domain/configuration/domain_xml_history/snapshot/20110908-165222603domain.xml"}},
        "server-operations" => undefined
    }
}

Take the latest snapshot of the host.xml for a particular host

Assume you have a host that is called master

[domain@localhost:9999 /]  /host=master:take-snapshot
{
    "outcome" => "success",
    "result" => {
        "domain-results" => {"step-1" => {"name" => "/home/anil/as7/jboss-as/build/target/jboss-as-7.1.0.Alpha1-SNAPSHOT/domain/configuration/host_xml_history/snapshot/20110908-165640215host.xml"}},
        "server-operations" => undefined
    }
}

How to get interface address

The attribute for interface is named "resolved-address". It's a runtime attribute so it does not show up in :read-resource by default. You have to add the "include-runtime" parameter.

./jboss-cli.sh --connect
Connected to standalone controller at localhost:9999
[standalone@localhost:9999 /] cd interface=public
[standalone@localhost:9999 interface=public] :read-resource(include-runtime=true)
{
     "outcome" => "success",
     "result" => {
         "any" => undefined,
         "any-address" => undefined,
         "any-ipv4-address" => undefined,
         "any-ipv6-address" => undefined,
         "criteria" => [("inet-address" => expression "${jboss.bind.address:127.0.0.1}")],
         "inet-address" => expression "${jboss.bind.address:127.0.0.1}",
         "link-local-address" => undefined,
         "loopback" => undefined,
         "loopback-address" => undefined,
         "multicast" => undefined,
         "name" => "public",
         "nic" => undefined,
         "nic-match" => undefined,
         "not" => undefined,
         "point-to-point" => undefined,
         "public-address" => undefined,
         "resolved-address" => "127.0.0.1",
         "site-local-address" => undefined,
         "subnet-match" => undefined,
         "up" => undefined,
         "virtual" => undefined
     }
}
[standalone@localhost:9999 interface=public] :read-attribute(name=resolved-address)
{
     "outcome" => "success",
     "result" => "127.0.0.1"
}

It's similar for domain, just specify path to server instance:

[domain@localhost:9999 /] /host=master/server=server-one/interface=public:read-attribute(name=resolved-address)
{
    "outcome" => "success",
    "result" => "127.0.0.1"
}

Remove Default Datasource and Driver

[standalone@localhost:9999 /] data-source remove --name=ExampleDS
[standalone@localhost:9999 /] /subsystem=datasources/jdbc-driver=h2:remove
{"outcome" => "success"}

Add a New JDBC Driver

standalone@localhost:9999 /] /subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql.jdbc,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
{"outcome" => "success"}

Add a New Datasource

[standalone@localhost:9999 /] data-source add \
>     --name=ApplicationDS \
>     --driver-name=postgresql \
>     --connection-url=jdbc:postgresql://localhost:5432/DemoDB \
>     --jndi-name=java:jboss/jdbc/ApplicationDS \
>     --user-name=demouser \
>     --password=password \
>     --use-ccm=false \
>     --max-pool-size=25 \
>     --blocking-timeout-wait-millis=5000 \
>     --new-connection-sql="set datestyle = ISO, European;"
[standalone@localhost:9999 /] data-source enable --name=ApplicationDS                  
[standalone@localhost:9999 /]

Add a New XA Datasource

[standalone@localhost:9999 /] xa-data-source add \
>     --name=ApplicationXADS \
>     --driver-name=postgresql \
>     --jndi-name=java:jboss/jdbc/ApplicationXADS \
>     --user-name=demouser \
>     --password=password \
>     --recovery-username= demouser \
>     --recovery-password = password \
>     --use-ccm=false \
>     --max-pool-size=25 \
>     --blocking-timeout-wait-millis=5000 \
>     --new-connection-sql="set datestyle = ISO, European;"
[standalone@localhost:9999 /] /subsystem=datasources/xa-data-source=ApplicationXADS/xa-datasource-properties=ServerName:add(value=localhost)
{"outcome" => "success"}
[standalone@localhost:9999 /] /subsystem=datasources/xa-data-source=ApplicationXADS/xa-datasource-properties=PortNumber:add(value=5432)
{"outcome" => "success"}
[standalone@localhost:9999 /] /subsystem=datasources/xa-data-source=ApplicationXADS/xa-datasource-properties=DatabaseName:add(value=DemoDB)
{"outcome" => "success"}
[standalone@localhost:9999 /] xa-data-source enable --name = ApplicationXADS
[standalone@localhost:9999 /]

Add a String Value into JNDI

[standalone@localhost:9999 /] /subsystem=naming/binding=java\:jboss\/param\/demoParam:add(value="Demo configuration value",binding-type=simple)
{"outcome" => "success"}

This value can then be looked up in code:

    @Resource(lookup="java:jboss/param/demoParam")
    private String demoParam;

Define a Security Domain Using a Database User Store, Howto Avoid a Full Server Reload Requests

This example shows usage of the operational header allow-resource-service-restart, which can be used in some cases to prevent server reload requests.

[standalone@localhost:9999 /] /subsystem=security/security-domain=DemoSecurityDomain:add
{"outcome" => "success"}
[standalone@localhost:9999 /] /subsystem=security/security-domain=DemoSecurityDomain/authentication=classic:add( \
    login-modules=[ \
        { \
            "code" => "Database", \
            "flag" => "required", \
            "module-options" => [ \
                ("unauthenticatedIdentity"=>"guest"), \
                ("dsJndiName"=>"java:jboss/jdbc/ApplicationDS"), \
                ("principalsQuery"=>"select password from users where username=?"), \
                ("rolesQuery" => "select name, 'Roles' FROM user_roles ur, roles r, user u WHERE u.username=? and u.id = ur.user_id and ur.role_id = r.id"), \
                ("hashAlgorithm" => "MD5"), \
                ("hashEncoding" => "hex") \
            ] \
        } \
    ] \
) {allow-resource-service-restart=true}
{"outcome" => "success"}

Scripted Configuration

Sample CLI configuration script

demo.cli
# Demo CLI script
connect
batch

# Add postgresql JDBC driver
/subsystem=datasources/jdbc-driver=postgresql:add( \
    driver-name=postgresql, \
    driver-module-name=org.postgresql.jdbc, \
    driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource \
)

# Add a non-XA datasource
data-source add \
    --name=ApplicationDS \
    --driver-name=postgresql \
    --connection-url=jdbc:postgresql://localhost:5432/DemoDB \
    --jndi-name=java:jboss/jdbc/ApplicationDS \
    --user-name=demouser \
    --password=password \
    --use-ccm=false \
    --max-pool-size=25 \
    --blocking-timeout-wait-millis=5000 \
    --new-connection-sql="set datestyle = ISO, European;"
data-source enable --name=ApplicationDS

# Add an XA datasource
xa-data-source add \
    --name=ApplicationXADS \
    --driver-name=postgresql \
    --jndi-name=java:jboss/jdbc/ApplicationXADS \
    --user-name=demouser \
    --password=password \
    --recovery-username= demouser \
    --recovery-password = password \
    --use-ccm=false \
    --max-pool-size=25 \
    --blocking-timeout-wait-millis=5000 \
    --new-connection-sql="set datestyle = ISO, European;"
/subsystem=datasources/xa-data-source=ApplicationXADS/xa-datasource-properties=ServerName:add(value=localhost)
/subsystem=datasources/xa-data-source=ApplicationXADS/xa-datasource-properties=PortNumber:add(value=5432)
/subsystem=datasources/xa-data-source=ApplicationXADS/xa-datasource-properties=DatabaseName:add(value=DemoDB)
xa-data-source enable --name = ApplicationXADS

# Bind a string value into JNDI
/subsystem=naming/binding=java\:jboss\/param\/demoParam:add(value="Demo configuration value",binding-type=simple)

# Create a Database authentication realm
/subsystem=security/security-domain=DemoAuthRealm:add
/subsystem=security/security-domain=DemoAuthRealm/authentication=classic:add( \
    login-modules=[ \
        { \
            "code" => "Database", \
            "flag" => "required", \
            "module-options" => [ \
                ("unauthenticatedIdentity"=>"guest"), \
                ("dsJndiName"=>"java:jboss/jdbc/ApplicationDS"), \
                ("principalsQuery"=>"select password from users where username=?"), \
                ("rolesQuery" => "select name, 'Roles' FROM user_roless ur, roles r, user u WHERE u.username=? and u.id = ur.user_id and ur.role_id = r.id"), \
                ("hashAlgorithm" => "MD5"), \
                ("hashEncoding" => "hex") \
            ] \
        } \
    ] \
)

# Execute and reload
run-batch
:reload

Execution of configuration script

[jboss-as-7.1.3.Final]$ bin/jboss-cli.sh --file=demo.cli
#1 /subsystem=datasources/jdbc-driver=postgresql:add(  driver-name=postgresql,  driver-module-name=org.postgresql.jdbc,  driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource  )
#2 data-source add  --name=ApplicationDS  --driver-name=postgresql  --connection-url=jdbc:postgresql://localhost:5432/DemoDB  --jndi-name=java:jboss/jdbc/ApplicationDS  --user-name=demouser  --password=password  --use-ccm=false  --max-pool-size=25  --blocking-timeout-wait-millis=5000  --new-connection-sql="set datestyle = ISO, European;"
#3 data-source enable --name=ApplicationDS
#4 xa-data-source add  --name=ApplicationXADS  --driver-name=postgresql  --jndi-name=java:jboss/jdbc/ApplicationXADS  --user-name=demouser  --password=password  --recovery-username= demouser  --recovery-password = password  --use-ccm=false  --max-pool-size=25  --blocking-timeout-wait-millis=5000  --new-connection-sql="set datestyle = ISO, European;"
#5 /subsystem=datasources/xa-data-source=ApplicationXADS/xa-datasource-properties=ServerName:add(value=localhost)
#6 /subsystem=datasources/xa-data-source=ApplicationXADS/xa-datasource-properties=PortNumber:add(value=5432)
#7 /subsystem=datasources/xa-data-source=ApplicationXADS/xa-datasource-properties=DatabaseName:add(value=DemoDB)
#8 xa-data-source enable --name = ApplicationXADS
#9 /subsystem=naming/binding=java:jboss/param/demoParam:jboss\/param\/demoParam:add(value="Demo configuration value",binding-type=simple)
#10 /subsystem=security/security-domain=DemoAuthRealm:add
#11 /subsystem=security/security-domain=DemoAuthRealm/authentication=classic:add(  login-modules=[  {  "code" => "Database",  "flag" => "required",  "module-options" => [  ("unauthenticatedIdentity"=>"guest"),  ("dsJndiName"=>"java:jboss/jdbc/ApplicationDS"),  ("principalsQuery"=>"select password from users where username=?"),  ("rolesQuery" => "select name, 'Roles' FROM user_roless ur, roles r, user u WHERE u.username=? and u.id = ur.user_id and ur.role_id = r.id"),  ("hashAlgorithm" => "MD5"),  ("hashEncoding" => "hex")  ]  }  ]  )
The batch executed successfully
{"outcome" => "success"}
[jboss-as-7.1.3.Final]$

Runtime

Get all configuration and runtime details from CLI

./bin/jboss-cli.sh -c command=":read-resource(include-runtime=true, recursive=true, recursive-depth=10)"

Add a log category

bin/jboss-cli.sh --connect "/subsystem=logging/logger=com.your.package.name:add(level=DEBUG)"

Toggle root logger level during runtime with out bouncing the server

In the development environment, on a running instance of JBoss, it is often desirable to turn up the level of the logs. For example, I have an application which would spit out
mega bytes of debug log statements if I had started the JBoss container with log level DEBUG. So for me, I would start the JBoss container with the default
log level (I believe the default is INFO). Then, as I am navigating the web application via the browser, I would come to a point where I would like to
turn up the verbosity of the log statements. So just before clicking on that link or button on the web page, I would open up a Terminal console and fire
up the jboss cli and modify the root-logger's log level to be DEBUG. Then, come back to the web page and click that link or button. And now, when one
views the server logs, there would be tons and tons of DEBUG statements.

In a production environment, this might be helpful when one needs more verbose logging for a short period of time. Then, when one is done collecting the log statements, one can then
switch the log level back to info. All the while the JBoss container does not need to be bounced.

1. On a freshly installed and running instance of jboss 7.1.1.Final, one would see the following when issuing a command to see the attribute
root-logger. The attribute 'root-logger' has not yet been defined.

[standalone@localhost:9999 /] /subsystem=logging/root-logger=ROOT:read-attribute(name=root-logger)
{    "outcome" => "failed",
    "failure-description" => "JBAS014792: Unknown attribute root-logger",
    "rolled-back" => true
}

2. Issue the command 'change-root-log-level' to modify the root logger to be of level DEBUG.

[standalone@localhost:9999 /] /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG)
{"outcome" => "success"}

3. Now, when one re-issues the read-attribute command on 'root-logger', it is defined and the level is displayed.

[standalone@localhost:9999 /] /subsystem=logging/root-logger=ROOT:read-attribute(name=root-logger)
{
    "outcome" => "success",
    "result" => {"level" => "DEBUG"}
}

Scripting

Windows and "Press any key to continue ..." issue

AS7 scripts for Windows end with "Press any key to continue ...". This behavior is useful when script is executed by double clicking the script but not when you need to invoke several commands from custom script (e.g. 'bin/jboss-admin.bat --connect command=:shutdown').

To avoid "Press any key to continue ..." message you need to specify NOPAUSE variable. Call 'set NOPAUSE=true' in command line before running any AS7 .bat script or include it in your custom script before invoking scripts from AS7.

Statistics

Read statistics of active datasources

/subsystem=datasources/data-source=ExampleDS/statistics=pool:read-resource(include-runtime=true)
/subsystem=datasources/data-source=ExampleDS/statistics=jdbc:read-resource(include-runtime=true)

or

/subsystem=datasources/data-source=ExampleDS:read-resource(include-runtime=true,recursive=true)
JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-13 13:21:29 UTC, last content change 2017-04-13 16:13:58 UTC.