Advanced WildFly CLI: variables and aliases

In this short tutorial we will explore two not so well known features of WildFly CLI: creating variables (and reading them at startup) and creating persistent alias for functions.

Let's start from the first: The CLI has a set function that can be used to assign a certain path of the server model to a variable. Example

set s1=/host=master/server=server-one

This is quite useful in domain mode as you can include references to host and profiles in variables so that you can easily replicate scripts on different servers. Example:

$s1/subsystem=datasources/data-source=ExampleDS:test-connection-in-pool

The problem here is that variables set within the CLI session will be lost at the end of the session. Luckily the .jbossclirc file comes to rescue us. Include the variables in this file (available in the "bin" folder of your server installation):

# .jbossclirc
set s1=/host=master/server=server-one
set s2=/host=master/server=server-two

Now restart the CLI and issue a set command to check the available variables:

[domain@localhost:9990 /] set
s1=/host=master/server=server-one
s2=/host=master/server=server-two

Good, now let's move on another topic, we will discuss about aliases. WildFly CLI can use aliases pretty mich the same you would do it in a Linux Box:

[domain@localhost:9990 /] alias ll='ls'
[domain@localhost:9990 /] ll
core-service                    management-client-content       domain-organization=undefined   name=Unnamed Domain             release-version=2.0.10.Final    
deployment                      path                            launch-type=DOMAIN              namespaces=[]                   schema-locations=[]             
deployment-overlay              profile                         local-host-name=master          process-type=Domain Controller  
extension                       server-group                    management-major-version=4      product-name=WildFly Full       
host                            socket-binding-group            management-micro-version=0      product-version=10.0.0.Final    
interface                       system-property                 management-minor-version=0      release-codename=Kenny

As for variables, the alias created in a CLI session are not persistent. Since the CLI is derived from the Aesh project (http://aeshell.github.io/) , aliases can be defined in the .aesh_aliases within the user's home folder (Not WildFly home!).

Let's test it. We will add the following alias in $HOME/.aesh_aliases

alias create='/subsystem=ejb3/strict-max-bean-instance-pool=demo:add(max-pool-size=10)'

Now start the CLI and test it:

[francesco@localhost bin]$ ./jboss-cli.sh -c
[standalone@localhost:9990 /] alias
alias create='/subsystem=ejb3/strict-max-bean-instance-pool=demo:add(max-pool-size=10)'
[standalone@localhost:9990 /] create
{"outcome" => "success"}

You could be also interested in the following tutorial:  Using properties in CLI scripts

Related articles available on mastertheboss.com

How do I get the list of MBeans with twiddle?

  JBoss provides a simple command line tool that allows for inte

How to count active session with twiddle ?

  There are some well known alternatives to count the number of

How do I run garbage collector from shell?

  You can suggest JBoss to run the garbage collector in differen

How do I check my application status from shell?

  This is a two process step: at first you need to retrieve the

How do you shut down multiple JBoss instances?

  Supposing you have configured 2 instances of JBoss, one on por

twiddle reference guide

Please note: twiddle is not available any more as default Command

Follow us on Twitter