Script-driven approach

From ControlTier

(Redirected from Script-driven Use Guide)
Jump to: navigation, search

The script-driven approach is one where your shell scripts drive the execution of the management process. This is in contrast to the model-driven approach.

The CTL command and control dispatching framework supports a procedural scripting model that lets you automate your management procedures in a distributed environment using a familiar script-driven approach. The node dispatch feature in the ControlTier command dispatcher also lets you execute your scripts and commands across sets of logically grouped nodes. Via the command dispatcher, you can also execute commands pre-defined in CTL modules.

You can write scripts that take advantage of the command dispatcher and modules in a number of ways. Your scripts can leverage various aspects of the ControlTier infrastructure such as the WebDAV, resource model data, job management and reporting. Your scripts can also build on a set of base and utilities modules and use them as a tool kit to help reduce complexity from your scripts, save implementation time and let you focus on the core management logic.

The Scripters cookbook contains a wide range of solutions for users following the script-driven approach.

Execute Commands

Scripting with ctl-exec

The ctl-exec command provides a convenient method to execute a locally defined script across a set of hosts. In this mode, ctl-exec first copies the script to the remote host and then executes it. The script can be defined in a file or read from standard input. The ctl-exec command supports several other useful features for executing commands across a set of hosts including: filtering logic, parallelism, and error handling.

Rather than require you to list nodes explicitly, the ctl-exec command lets you dispatch to a set of nodes through filter-based lookup options. Each node registered to a ControlTier project includes a standard set of node metadata that you can use in your filter specification. Node tags are useful to create a symbolic name for a group of nodes that share a characteristic, like a particular application they might all have resident or a role they play within the infrastructure.

You can run any script from the ControlTier server host across a set of tagged nodes using ctl-exec with this usage format:

ctl-exec -p project -I tags=tagname -s script

Or you can have ctl-exec read the script code from stdin. Here's an example using the Unix here doc form:

ctl-exec -p project -I tags=tagname -S <<EOS
script statement 1;
script statement 2;
EOS

Letting ctl-exec do the dispatching for you, reduces complexity from the script writing. With ctl-exec as a front end, you avoid writing iteration and remote command dispatch logic inside your scripts (see Replace your SSH loop script). This lets you write scripts from the point of view of a single target node and thus they become easier to test and trouble shoot.

The diagram below illustrates ctl-exec executing a script file called "simpleTomcat.sh" across nodes that have been tagged "simpleTomcat":

Example-ctl-exec-scripts-screenshot.png

The specific ctl-exec usage to support the scenario shown in the diagram above is shown here:

ctl-exec -p demo -I tags=simpleTomcat -s simpleTomcat.sh


Putting it all together

The preceding sections described a number of features that, individually, might be useful to a script writer. Their usefulness increase when you combine them. Of course, your scripts drive the tasks that make up your process and so there is no hard and fast rule about the "best" way to utilize the ControlTier framework. Instead, you can consider a number of design patterns that you can adapt to your needs. Here are a few general patterns:

The Scripted appserver war deployment example walks through many of these patterns over a series of iterations and can give you an idea how you might transform your scripts and approach.

Personal tools
Namespaces
Variants
Actions
Navigation
Communication
Development
Toolbox
Print/export