A simple, highly available resource can be defined as an application resource that manages one application.
For illustrative purposes we created a simple Tcl/Tk[1] script. You will probably already have an application or two identified for this task.
Create the script.
# cat > xhostname #!/usr/bin/wish set hname [exec hostname -s] set clarg [lindex $argv 0] wm minsize . 350 30 wm title . "$argv0 on $hname $clarg" button .hostname -font helvb24 -text $hname -command { exit } pack .hostname -padx 10 -pady 10 ^D
Change the permission bits so that the program can execute.
# chmod u+x ./xhostname
Change the ownership and group to root and system respectively.
# chown root:system ./xhostname
Test the script.
[molari] # ./xhostname
Figure 24-1 shows the xhostname script in action.
Figure 24-1: The xhostname Tcl/Tk Script
Using the caa_profile(8) command we can create an application to manage the xhostnamescript. Note, use the full pathname of the application.
# caa_profile -create myFirstCAA_app -t application -B /code/caa/xhostname
The caa_profile command will create two files: a profile and an action script.
# ls /var/cluster/caa/*/myFirstCAA_app* /var/cluster/caa/profile/myFirstCAA_app.cap /var/cluster/caa/script/myFirstCAA_app.scr
Since the xhostname script is designed to display in an X Window System environment and run in the foreground, we will need to modify the action script (myFirstCAA_app.scr).
Locate the main case statement and add the DISPLAY environment variable before it.
Find these lines: | case $1 in 'start') |
Add a line above: | |
To display on a specific system: | export DISPLAY= "yourSystemNameHere :0" |
To display on the member where the resource is running: | export DISPLAY="$(/sbin/hostname -s):0" |
Then locate the line in the script where the command is executed. It will be a few lines below the main case statement, in the 'start' case.
Line | Original | Proposed Modification | |
---|---|---|---|
V5.0A | – 361: | $START_APPCMD >> ${LOG} | $START_APPCMD >> ${LOG}& |
V5.1 | – 320: | out='$START_APPCMD' | out= $($START_APPCMD) & |
V5.1B | – 322: | $START_APPCMD >$tmpfile 2>&1 | $START_APPCMD >$tmpfile 2>&1& |
Make sure the action script works. In this case, if the action script successfully starts the xhostname script as shown in Figure 24-1 and exits successfully, the action script does what we expect.
# /var/cluster/caa/script/myFirstCAA_app.scr start
If that works, then verify that the stop entry point works as well.
# /var/cluster/caa/script/myFirstCAA_app.scr stop
This is a very simple example and testing your application resource action script may need to be more thorough. See section 23.5 for more information.
Once the action script has been tested, validate the resource profile.
# caa_profile -validate myFirstCAA_app
If the profile validates, register the resource. For more information, see section 23.4.7.
# caa_register myFirstCAA_app
Once the resource is successfully registered, start the resource. For more information, see section 23.4.11.
# caa_start myFirstCAA_app Attempting to start 'myFirstCAA_app' on member 'molari' Start of 'myFirstCAA_app' on member 'molari' succeeded.
After starting the resource, relocate it for good measure.
# caa_relocate myFirstCAA_app Attempting to stop 'myFirstCAA_app' on member 'molari' Stop of 'myFirstCAA_app' on member 'molari' succeeded. Attempting to start 'myFirstCAA_app' on member 'sheridan' Start of 'myFirstCAA_app' on member 'sheridan' succeeded.
[1]Tcl is a general-purpose scripting language written by Dr. John K. Ousterhout. Tk is an X Windows System toolkit based on Tcl. For more information, see the Tcl Developer's Site at http://dev.scriptics.com/.