WildFly CLI Scripting: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(27 intermediate revisions by the same user not shown)
Line 2: Line 2:


* [[WildFly CLI Operations#Subjects|CLI Operations]]
* [[WildFly CLI Operations#Subjects|CLI Operations]]
=Overview=
This article describes various aspects of using CLI as a command-line execution tool - as opposite to an interactive session tool.


=Connection to a Host Controller=
=Connection to a Host Controller=
Line 13: Line 17:
=Executing a Single Command=
=Executing a Single Command=


<pre>
Any word or phrase without white spaces in it is assumed to be a command. The <tt>--command</tt> argument optionally precedes it.
jboss-cli.sh -c command="..."
 
</pre>
After a command is executed, the CLI will terminate the session.


Example:
Example:


<pre>
<pre>
jboss-cli.sh -c command="deploy ./test.war --server-groups=web-frontend"
jboss-cli.sh -c [--command=]ls
</pre>
</pre>


=Executing a Sequence of Commands Listed in a File=
If a command requires space-separated arguments, command and the arguments should be enclosed is single quotes:


<pre>
<pre>
jboss-cli.sh -c --file=./commands.cli
jboss-cli.sh -c [--command=]'deploy ./test.war --server-groups=web-frontend'
</pre>
</pre>


where <tt>/commands.cli</tt>'s content is similar to:
=Executing Multiple Commands Specified on Command Line=
 
In order to execute multiple commands (individual commands are assumed not to contain spaces),  specify them in a comma separated list at the end of the argument list. ''Spaces are  not allowed''. The <tt>--commands</tt> argument optionally precedes it.
 
After the last command in the sequence is executed, the CLI will terminate the session.
 
Example:


<pre>
<pre>
jboss-cli.sh -c [--commands=]ls,pwd
</pre>
</pre>


=Script Example=
If a command requires space-separated arguments, command and the arguments should be enclosed is single quotes:


<pre>
<pre>
batch
jboss-cli.sh -c [--commands=]ls,'deploy ./test.war --server-groups=web-frontend'
# Configure the connection from main server to "one" and "two"
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-ejb:add(host=localhost, port=4647)
 
# add security realm
/core-service=management/security-realm=ejb-security-realm:add()
/core-service=management/security-realm=ejb-security-realm/server-identity=secret:add(value=cXVpY2stMTIz)
 
# add the outbound connections to the remoting subsystem
/subsystem=remoting/remote-outbound-connection=remote-ejb-connection:add(outbound-socket-binding-ref=remote-ejb, security-realm=ejb-security-realm, username=quickuser)
/subsystem=remoting/remote-outbound-connection=remote-ejb-connection/property=SASL_POLICY_NOANONYMOUS:add(value=false)
/subsystem=remoting/remote-outbound-connection=remote-ejb-connection/property=SSL_ENABLED:add(value=false)
run-batch
</pre>
</pre>


=Deployment Script=
=Executing a Sequence of Commands Listed in a File=
 
==Separated Bash Launcher and CLI Script==
 
<tt>deploy.sh</tt>:


<pre>
<pre>
#!/bin/bash
jboss-cli.sh -c --file=./commands.cli
 
reldir=$(dirname $0)
 
${JBOSS_HOME}/bin/jboss-cli.sh -c --file=${reldir}/deploy.cli
</pre>
</pre>


<tt>deploy.cli</tt>:
where <tt>/commands.cli</tt> may contain multiple commands, one per line. Individual commands may contain spaces. Example:


<pre>
<pre>
batch
pwd
#deploy target/playground.war --server-groups=main-server-group
ls
deploy target/playground.war --force
deploy servlet-example.war --force
run-batch
</pre>
</pre>


==Coalesced Scripts==
=Sending Commands into <tt>jboss-cli.sh</tt>'s <tt>stdin</tt>=
 
This is where you can use bash variables.


<pre>
<pre>
#!/bin/bash
#!/bin/bash
# ...


jboss-cli.sh -c <<EOF
jboss-cli.sh -c <<EOF
#
# comments are permitted; they should be prefixed by '#'
#
batch
batch
#deploy target/playground.war --server-groups=main-server-group
#deploy target/playground.war --server-groups=main-server-group
Line 91: Line 80:
EOF
EOF
</pre>
</pre>
==Examples==
<blockquote style="background-color: AliceBlue; border: solid thin LightSteelBlue;">
:https://github.com/NovaOrdis/playground/tree/master/jboss/cli/bash-script-examples<br>
</blockquote>


=Using Variables=
=Using Variables=
<font color=red>TODO:


* JBoss EAP 6 : using variables in CLI scripts (jboss-cli.sh) https://access.redhat.com/solutions/321513
* JBoss EAP 6 : using variables in CLI scripts (jboss-cli.sh) https://access.redhat.com/solutions/321513


See [[#Coalesced_Scripts|coalesced scripts]] above.
Also see [[#Sending_Commands_into_jboss-cli.sh.27s_stdin|Sending Commands into <tt>jboss-cli.sh</tt>'s <tt>stdin</tt>]] above.


<font color=red>
I've seen this example, how does it work, how is Host1_Name defined?
I've seen this example, how does it work, how is Host1_Name defined?


Line 108: Line 103:


</font>
</font>
=<tt>batch</tt>/<tt>run-batch</tt>=
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
:[[WildFly_CLI_Concepts#Batch|WildFly CLI Concepts - Batch]]
</blockquote>

Latest revision as of 14:48, 27 March 2017

Internal

Overview

This article describes various aspects of using CLI as a command-line execution tool - as opposite to an interactive session tool.

Connection to a Host Controller

In order to be able to interact with a host controller, CLI must be connected. For options on how to connect see:

Connect to a Controller

Executing a Single Command

Any word or phrase without white spaces in it is assumed to be a command. The --command argument optionally precedes it.

After a command is executed, the CLI will terminate the session.

Example:

jboss-cli.sh -c [--command=]ls

If a command requires space-separated arguments, command and the arguments should be enclosed is single quotes:

jboss-cli.sh -c [--command=]'deploy ./test.war --server-groups=web-frontend'

Executing Multiple Commands Specified on Command Line

In order to execute multiple commands (individual commands are assumed not to contain spaces), specify them in a comma separated list at the end of the argument list. Spaces are not allowed. The --commands argument optionally precedes it.

After the last command in the sequence is executed, the CLI will terminate the session.

Example:

jboss-cli.sh -c [--commands=]ls,pwd

If a command requires space-separated arguments, command and the arguments should be enclosed is single quotes:

jboss-cli.sh -c [--commands=]ls,'deploy ./test.war --server-groups=web-frontend'

Executing a Sequence of Commands Listed in a File

jboss-cli.sh -c --file=./commands.cli

where /commands.cli may contain multiple commands, one per line. Individual commands may contain spaces. Example:

pwd
ls
deploy servlet-example.war --force

Sending Commands into jboss-cli.sh's stdin

#!/bin/bash

jboss-cli.sh -c <<EOF
#
# comments are permitted; they should be prefixed by '#'
#
batch
#deploy target/playground.war --server-groups=main-server-group
deploy target/playground.war --force
run-batch
EOF

Examples

https://github.com/NovaOrdis/playground/tree/master/jboss/cli/bash-script-examples

Using Variables

TODO:

Also see Sending Commands into jboss-cli.sh's stdin above.

I've seen this example, how does it work, how is Host1_Name defined?

/host=$Host1_Name:write-local-domain-controller
reload --host=$Host1_Name

batch/run-batch

WildFly CLI Concepts - Batch