18.2. Creating the Wrapper Script and .conf File

The wrapper script takes command-line arguments and calls the JBoss ON CLI with one of the scripts as argument. The command-line arguments themselves are defined in the JBoss ON JavaScript files.
This wrapper script makes a few assumptions:
  • The wrapper script is run as a regular user, which means that any JavaScript files must be accessible to a regular user.
  • The scripts are located in a scripts/ directory that is in the same directory as the wrapper script.
  • A separate configuration file defines connection information for the JBoss ON server.
  • Each JavaScript file is invoked by a separate CLI command invocation, defined in the wrapper.
  • Any options or information required by the JBoss ON CLI command is defined in the JavaScript file and can, potentially, be passed with the wrapper script as an option.
# groupcontrol
# ------------
# This is a simple wrapper script for all the java script scripts in this folder.
# Start this script with some parameters to automate group handling from within the
# command line.
# With groupcontrol you can do the following:
#   create   : Create a new group
#   addMember: Add a new EAP instance to the specified group
#   status   : Print the status of all resources of a group
#   start    : start all EAP instances specified by group name
#   deploy   : Deploys an application to all AS instances specified by group name
#   avail    : Runs an availability operation on all discovered agent instances
#   metrics  : Gets the specified metric value for all AS instances specified by group name
## Should not be run as root.
if [ "$EUID" = "0" ]; then
   echo " Please use a normal user account and not the root account"
   exit 1
## Figure out script home
MY_HOME=$(cd `dirname $0` && pwd)
## Source some defaults
. $MY_HOME/groupcontrol.conf
## Check to see if we have a valid CLI home
if [ ! -d ${JON_CLI_HOME} ]; then
     echo "JON_CLI_HOME not correctly set. Please do so in the file"
     echo $MY_HOME/groupcontrol.conf
     exit 1
# If JBoss ON_PWD is given then use it as argument. Else let the user enter the password
if [ "x$JON_PWD" == "x" ]; then
#echo "Calling groupcontrol with $RHQ_OPTS"
usage() {
     echo "  Usage $0:"
     echo "  Use this tool to control most group related tasks with a simple script."
     echo "  ------------------------------------------------------------------------- "
Each command that the wrapper should define has a doCommand() section which defines the JBoss ON CLI command to run and the JavaScript file to use.
doDeploy() {
     $JON_CLI_HOME/bin/rhq-cli.sh $RHQ_OPTS -f $SCRIPT_HOME/deploy.js $2 $3

doCreate() {
     $JON_CLI_HOME/bin/rhq-cli.sh $RHQ_OPTS -f $SCRIPT_HOME/group.js $2
doAddMember() {
     $JON_CLI_HOME/bin/rhq-cli.sh $RHQ_OPTS -f $SCRIPT_HOME/addMember.js $2 $3 $4
doStatus() {
     $JON_CLI_HOME/bin/rhq-cli.sh $RHQ_OPTS -f $SCRIPT_HOME/status.js $2

doRestart() {
     $JON_CLI_HOME/bin/rhq-cli.sh $RHQ_OPTS -f $SCRIPT_HOME/restart.js $2 

doAvail() {
     $JON_CLI_HOME/bin/rhq-cli.sh $RHQ_OPTS -f $SCRIPT_HOME/avail.js
doMetrics() {
     $JON_CLI_HOME/bin/rhq-cli.sh $RHQ_OPTS -f $SCRIPT_HOME/metrics.js $2 $3

case "$1" in
	doDeploy $*
	doCreate $*
	doAddMember $*
	doStatus $*
	doRestart $*
	doAvail $*
	doMetrics $*
        usage $*
This script uses a configuration file, groupcontrol.conf, which defines the connection information to connect to the JBoss ON server (which is required by the JBoss ON CLI).
## This file contains some defaults for the groupcontrol script
# The user you want to connect with
# if you omit the password here, you'll be prompted for it.