Corus Scripts

Basics

All the commands provided as part of the Corus command-line interface can also be executed as part of scripts (which are simply text files containing Corus commands).

There are three ways to execute a script:

  1. Through the script command available as part of the Corus CLI.
  2. By specifying the -s option when invoking the CLI; the option is expected to consist of the path to the script to execute.
  3. Through the Corus Maven plugin (which is the subject of a specific section of this guide).

Here's an example of such a script:

kill all -w -cluster 
undeploy all -cluster
deloy myapp-*.zip -cluster
exec -e myapp -cluster

The content of the script above could be saved in a plain text file and executed from the CLI like this:

coruscli -s <path_to_script>

The kill, exec and restart commands all support a -w option, meaning “wait", which forces the command-line to block until the command has completed on the server-side prior to moving on to the next command. This is convenient in the case of scripted deployments.

For example, in the above, it is necessary to wait that the kill has completed prior to invoking undeploy, since that command will result in an error if processes corresponding to the distribution to undeploy are still running.

Furthermore, a script can be invoked from another, using the script command (the match and ripple command also support invoking scripts):

undeploy all
script deploy.corus
echo "deployment completed"

Using variables

Note that scripts can take variables of the form ${<variable_name>}, as shown below:

undeploy all
deploy ${user.dir}/package/mydistribution.zip
echo "deployment completed"

Loading properties kept in Corus to use as variables

As of release 4.5, properties added to Corus with conf add can be loaded on the client-side in Corus scripts, and used in such scripts to perform variable interpolation.

Imagine that you've pushed a property to Corus, as such:

conf add -p app.env=prod -cluster

In order to be able to use that property has a variable on the client-side (that is, when executing script from the CLI), you need to use conf load:

conf load 
conf add ${user.dir}/${app.env}/app.properties

Note our use of the ${app.env} variable, whose value will correspond to the matching property previously loaded from the Corus instance to which the CLI is currently connected.

Commands following conf load can use the properties that were loaded as variable values (that is, the properties just loaded are immediately available in the current script, for subsequent commands).

To load properties corresponding to a given category, use the -c option. Say for example we've associated the app.env property with the environment category:

conf add -p app.env=prod -c environment -cluster

We can then load properties corresponding to a given category like so:

conf load -c environment

You can also match properties with a name pattern:

conf load -p app.* -c environment