A Closer Look at the CLI
In order to be able to tailor a Corus installation to specific needs, one needs understanding the file layout, and the main configuration elements.
- Managing in Batch
Managing in Batch
If you are handling a relatively large number of processes/distributions/hosts, you have an interest in using features of the CLI that allow for batch manipulation.
Many commands support pattern-matching (ls, undeploy, exec, ps, etc.). Here are a few example:
ls -d * -v * exec -d * -v * -n * -p test undeploy -d * -v * ps -d * -v *
For lack of a better term, we have classified some commands under the "aggregate" category. These commands are match and count: they work on the results of other commands, performing filtering and counting, respectively.
The count command is used to count the number of results returned by given commands - which are expected to return lists (such as ls, port ls, conf ls, etc.). The syntax goes as follows:
The following all make sense in the context of count:
count hosts count ls -d * -v * -cluster count ps -d * -v *
The count command also supports the -a option - which stands for "assertion". This is used to assert that the number of items returned by the subsequent command corresponds to the one specified by the -a option. For example, to assert that the cluster as a certain number of hosts, you can do the following:
count -a 10 hosts
If the assertion fails, it generates an error and execution aborts. This can be useful in the context of sanity checks prior to deployment.
When managing large clusters, it can happen that commands listing information (such as ls, conf ls, port ls, ps, and the likes) return too much data at once to be easily viewable by system administrators. This is where the match command comes handy (working somehow like grep in Unix/Linux). In the same manner as count, match takes a subsequent command as an argument, applying filtering to that command's output, based on a specified pattern (Ant-like patterns are supported, not regexes).
In addition, match also can be provided with a Corus script to be executed against the hosts for which the matching was successful - in this case, the command is actually match apply. The syntax of the command is given below:
match [apply <script_path>] <pattern> <command>
Here are a few examples:
|match act. ps -cluster||Displays the currently active processes, cluster-wide.|
|match 192.**.10* hosts||Displays the hosts whose IP address corresponds to the given pattern.|
|match apply restart.corus stal* ps -cluster||Applies the restart.corus script to the hosts returning processes that are stale.|
Using match in conjunction with count can be quite convenient:
count match stal. ps -cluster
The 'all' Shortcut
When performing undeploy, kill, etc., it can be annoying to have to provide all the options when we want to match everything (such as in kill -d * -v * -n *).
As a convenience, many commands support the all keyword, as illustrated by the following examples:
undeploy all -cluster kill -all -cluster restart -all
The CLI supports a few productivity features that make using it more convenient
Corus supports sorting the output using predefined so-called flags - used in the context of the sort command.
This section provides an overview of output sorting - for a complete list of the sort flags that are available, type man sort in the CLI. The following are available in terms sorting features:
- Turning specified sort flags on or off.
- Pushing sort flag configuration to Corus, and clearing such a configuration from Corus.
- Listing the available sort flags.
To sort output by host name and IP address (in that order), type:
sort on hn,hi
Multiple sort flags can be specified, through a comma-delimited list (without spaces). Sorting can be turned off. For example, to turn off sorting by IP, type:
sort off hi
Sort flag configuration can be pushed to the Corus node to which the CLI is currently connected (or to all nodes in the cluster), as follows:
sort push hn,hi -cluster
Flags pushed to a Corus node are automatically loaded when the CLI connects to that node. As a corollary, sort flags can be cleared from the current Corus node, or from the whole cluster:
sort clear -cluster
The sort clear command deletes all flags - it does not support clearing only specific flags. To view the flags that are currently specified, type:
It may be convenient to create aliases for commands, especially when those are used repetitively and take multiple arguments.
The alias command is intented just for creating such aliases. These aliases are then interpreted as "normal" commands by the CLI. The following creates an alias named ka, which will act as a synonym for the kill all -cluster command:
alias -n ka -c "kill all -cluster"
If an alias is specified with no arguments/options, then such arguments and options can be passed to it at invocation time. For example, let's redefine our ka alias:
alias -n ka -c "kill"
It can then be invoked as follows:
ka all -cluster
If both the alias and the aliased command have arguments/options, those of the alias will override those passed at the command line.
For example, say we define our ka alias as in our first example:
alias -n ka -c "kill all -cluster"
If we invoke the alias as follows:
ka -d * -v * -n * -cluster
Then the options and arguments passed to the command will be ignored, since the alias has such options and arguments defined already. So these will override the ones of the command. Therefore, that actually executed command will be kill all -cluster.
Executing Commands at CLI Startup
Linux/Unix and other OSes support loading a user-specific script that sets up the environment when the user launches a terminal session. Similarly, when the CLI starts up, it searches for a Corus script at:
The content of the .profile.corus script is expected to consist of Corus commands - it is a plain-vanilla Corus script, which may hold any command that the user sees fit. It is a convenient place to define aliases, sorting (see the two previous sections), etc.