Sometimes installing an application and setting up an environment for it may consist of deploying multiple application archives and modifying server configurations (adding new services, adjusting some settings, etc). Doing all this by hand every time you need to deploy and undeploy the application could be a tedious task. One thing that could help here is batches. Another one, which was introduced specifically to make it easier to install/uninstall complex applications, is CLI deployment archive.
A CLI deployment archive is a JAR file with .cli extension containing application archives that should be deployed and CLI script files containing commands and operations: one script file contains commands and operations that deploy the application archives and set up the environment and the other one undeploys the application archives and cleans up the environment.
Let's look at a simple example. Suppose, we have a simple CLI archive with three WAR files and two scripts
{code}[xxx@xxx xxx]$ jar -tf test.cli
deployment0.war
deployment1.war
deployment2.war
deploy.scr
undeploy.scr{code}
deploy.scr:
{code}
deploy deployment0.war
deploy deployment1.war
deploy deployment2.war{code}
undeploy.scr:
{code}
undeploy deployment0.war
undeploy deployment1.war
undeploy deployment2.war{code}
This archive can be deployed with a simple deploy command
{code}
[standalone@localhost:9999 /] deploy test.cli
#1 deploy deployment0.war
#2 deploy deployment1.war
#3 deploy deployment2.war
[standalone@localhost:9999 /]{code}
By default, the deploy command handler will look for the deploy.scr script file in the archive, so unless the script is named differently, there is no need to specify the script name.
Undeploying is easy as well
{code}
[standalone@localhost:9999 /] undeploy --path=test.cli
#1 undeploy deployment0.war
#2 undeploy deployment1.war
#3 undeploy deployment2.war
[standalone@localhost:9999 /]{code}
Note, that you should specify the path to the archive as a value of the --path argument of the undeploy command. If you try undeploy test.cli it will try looking for test.cli among the registered deployed application archives and will fail. Only deployment0.war, deployment1.war and deployment2.war will be registered deployments. Argument-wise, it's a little inconsistent with the deploy command but, although, deploy test.cli is a shortcut for
{code}
[standalone@localhost:9999 /] deploy --path=test.cli
#1 deploy deployment0.war
#2 deploy deployment1.war
#3 deploy deployment2.war
[standalone@localhost:9999 /]{code}
In this complete form, this scenario is consistent, i.e. you use --path for both deploy and undeploy commands.
As with the deploy, undeploy will look for the undeploy.scr in the CLI arhive to uninstall the application and clean-up the environment. If your scripts are named differently (perhaps, you have different install/uninstall scripts in the same archive) you can use the --script argument to specify which one you want to execute.
Let's add couple of alternative scripts to our archive.
{code}
[xxx@xxx xxx]$ jar -tf test.cli
deployment0.war
deployment1.war
deployment2.war
deploy.scr
undeploy.scr
install.scr
uninstall.scr{code}
install.scr deploys only two deployments out of three
{code}
deploy deployment0.war
deploy deployment1.war{code}
And uninstall.scr undeploys them
{code}
undeploy deployment0.war
undeploy deployment1.war{code}
Now we can choose our non-default script to install
{code}
[standalone@localhost:9999 /] deploy --path=test.cli --script=install.scr
#1 deploy deployment0.war
#2 deploy deployment1.war
[standalone@localhost:9999 /]{code}
and uninstall the applications
{code}
[standalone@localhost:9999 /] undeploy --path=test.cli --script=uninstall.scr
#1 undeploy deployment0.war
#2 undeploy deployment1.war
[standalone@localhost:9999 /]{code}
Comments