Red Hat Training
A Red Hat training course is available for Red Hat JBoss Operations Network
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.
#!/bin/bash # # 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 fi ## Figure out script home MY_HOME=$(cd `dirname $0` && pwd) SCRIPT_HOME=$MY_HOME/scripts ## 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 fi RHQ_OPTS="-s $JON_HOST -u $JON_USER -t $JON_PORT" # If JBoss ON_PWD is given then use it as argument. Else let the user enter the password if [ "x$JON_PWD" == "x" ]; then RHQ_OPTS="$RHQ_OPTS -P" else RHQ_OPTS="$RHQ_OPTS -p $JON_PWD" fi #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 'deploy') doDeploy $* ;; 'create') doCreate $* ;; 'addMember') doAddMember $* ;; 'status') doStatus $* ;; 'restart') doRestart $* ;; 'avail') doAvail $* ;; 'metrics') doMetrics $* ;; *) usage $* ;; esac
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 ## JON_CLI_HOME=cliRoot/rhq-remoting-cli-4.9.0.JON320GA JON_HOST=localhost JON_PORT=7080 # The user you want to connect with JON_USER=rhqadmin # if you omit the password here, you'll be prompted for it. JON_PWD=rhqadmin