Until now, we have seen CLI commands as part of an interactive session. You can, however, execute commands in no-interactive fashion, adding them in a file, just as a shell script. Suppose you have created a sample test.cli file used to issue a redeploy command:
connect
deploy Utility.jar –force
Then, as Windows user, launch the CLI with the –file parameter:
jboss-admin.bat –file=test.cli
The equivalent command for Unix users will be:
./jboss-admin.sh –file=test.cli
Another way to execute commands in a non-interactive way, is passing the –commands parameter to the CLI, containing the list of commands lines separated by a comma. For example, the previous script can be also executed this way: (Windows users):
jboss-admin.bat –commands=”connect,deploy Utility.jar –force”
Connected to standalone controller at localhost:9999
‘Utility.jar’ re-deployed successfully.
Closed connection to localhost:9999
The equivalent script for Unix users will be:
./jboss-admin.sh –commands=”connect,deploy Utility.jar –force”
When you are executing the CLI in a non-interactive way, you can redirect the output to a file, which would be otherwise be printed on the screen. Just as for a shell command, use the > operator to redirect the output:
jboss-admin.bat –file=test.cli > out.log # Windows
./jboss-admin.sh –file=test.cli > out.log # Linux
Well, everyone makes mistakes, but many of them are preventable. Whenever you are performing massive changes to your configuration, it’s always a good idea to save copies of your work. That’s where snapshots come in; one of the advantages of using the CLI, is the ability to create snapshots of the configuration, which are stored in its history folder.
The history folder is located just one step under the configuration of the AS. Standalone servers have a history folder named standalone_xml_history that, at start up, contains the following files:
The domain configuration, on the other hand, provides two backup directories both for the domain configuration file and the host configuration file. These folders are named domain_xml_history and host_xml_history, respectively.
To make the reading not too verbose, we will describe the snapshot mechanisms using a standalone server. The same rules de facto also applies also for domain servers, bearing in mind that the AS takes snapshots of both the domain.xml
and host.xml
file. Let’s see now what the history files are about. The standalone.initial.xml contains
the original AS configuration file. This file is never overwritten by the AS.
Each time you reboot the application server, a copy of your successful boot configuration is stored into the snapshot folder using the timestamp naming format YYYYMMDD-HHMMMSstandalone.xml. The following is a snapshot taken by the application server on a hot day of August (8th) 2011 at 12:11.
The current folder, on the other hand, is used as temporary folder for storing changes in the configuration that happened in the current session. Each change in the application server configuration model will result in a file named standalone.v[n].xml
will be created. Here n is the change number applied (standalone.v1.xml for the initial configuration, standalone.v2.xml for the first change, and so on).
Frequently asked Jboss Interview Questions
When the application server is restarted, these files are moved into a timestamped folder into the standalone_xml_history top folder. As you can see from the next screenshot, changes during the last session are moved at reboot into the folder 20110808-122628937:
As suggested by the earlier warning, you can also take snapshots on demand whenever you need it. Snapshots created by the user are stored directly in the snapshot folder (along with successful server boot’s snapshots). In order to take a snapshot of the configuration, just issue the take-snapshot command and the CLI will back up your
configuration:
[standalone@localhost:9999 /] :take-snapshot
{
“outcome” => “success”,
“result” => {“name” => “C:jboss-as-
7.0.0.Finalstandaloneconfigurationstandalone_xml_historysnapshot20110726-
223444446standalone.xml”
}
}
You can check the list of available snapshots by using the list-snapshots command:
[standalone@localhost:9999 /] :list-snapshots
{
“outcome” => “success”,
“result” => {
“directory” => “C:jboss-as-
7.0.0.Finalstandaloneconfigurationstandalone_xml_historysnapshot”,
“names” => [
“20110725-064943007standalone.xml”,
“20110725-222015995standalone.xml”,
“20110726-212857046standalone.xml”,
“20110726-223444446standalone.xml”
]
}
}
You can, at any time, delete a particular snapshot using the delete-snapshot command, which requires the snapshot name as parameter. Suppose we would need to delete the snapshot we’ve just created:
[standalone@localhost:9999 /] :delete-snapshot(name=”20110726- 223444446standalone.xml”)
{“outcome” => “success”}
All commands which are executed within a CLI session are stored in an history, much like shell commands for Unix systems. CLI commands are kept in memory and also persisted on the file system in a file named .jboss-cli-history placed in the user’s home directory. You will notice that the commands entered in previous sessions are part of the history, up to the latest 500 commands (default history size).
If you want to have a look at the CLI history, just issue the history command:
[standalone@localhost:9999 /]history
You can also use the arrow keys to go navigate back and forth in the history of commands and operations, much like you would do with a Linux bash shell.
The history command supports three optional arguments, which can be used to temporarily disable/enable or clear the history. In the following table, we just mention their outcome:
Name | Dates | |
---|---|---|
JBoss Training | Nov 02 to Nov 17 | View Details |
JBoss Training | Nov 05 to Nov 20 | View Details |
JBoss Training | Nov 09 to Nov 24 | View Details |
JBoss Training | Nov 12 to Nov 27 | View Details |
Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.