#!/bin/bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Package: OurGrid 3.3.1 # # Description: User Agent Administration Tool # # Copyright (c) 2002-2006 Universidade Federal de Campina Grande # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #!/bin/sh # Find MGROOT: # $0 is the executable $MGROOT/bin/mygrid or a link to it # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - findmgroot(){ PRG="$0" while [ -h "$PRG" ]; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '.*/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`/"$link" fi done PRGDIR=`dirname "$PRG"` MGROOT=`cd "$PRGDIR/.." ; pwd` if [ -z "$MGROOT" ]; then echo "ERR_MGROOT_NOT_DEFINED" return $ERR_MGROOT_NOT_DEFINED else return $OK fi } # Set the $VAR $BIN and $LIB # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - setenvvars(){ BIN=$MGROOT/bin LIB=$MGROOT/lib if [ -z "$BIN" ] || [ -z "$LIB" ] ; then echo "ERR_VARS_NOT_DEFINED" return $ERR_VARS_NOT_DEFINED else return $OK fi } # Set the MGROOT and CLASSPATH including all libraries from $MGROOT/lib # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - setclasspath(){ PWD_=`pwd` mypath=. cd "$LIB" for i in `/bin/ls *.jar`; do myclass="$LIB/$i" mypath=$mypath:$myclass done cd "$PWD_" CLASSPATH="$mypath:$MGROOT/resources/doctorPlugins" if [ -z "$CLASSPATH" ]; then return $ERR_CLASSPATH_NOT_DEFINED else return $OK fi } # Set the JAVAOPTION to invoke OurGrid classes # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - setjavaoptions(){ JAVAOPTIONS=" -classpath $CLASSPATH -DMGROOT=$MGROOT " } usage(){ progname=`basename $0` echo "Usage: $progname command sdf" echo "where command is:" echo echo " start -- Tries to start all user agents from the specified SDF" echo " stop -- Tries to stop all user agents from the specified SDF" echo " status -- Tests all user agents from the specified SDF" echo " restart -- Tries to restart all user agents from the specified SDF" echo " clean -- Tries to clean the environment, deleting the user's .ourgrid and the uasconf directory" echo echo "sdf ---> site description file" echo echo "For OurGrid updates and additional information, see the " echo "OurGrid Project home page at http://www.ourgrid.org/ " exit $ERR_STD_MISUSE } # Tries to start all User Agents from the specified SDF start() { java -DMGROOT="$MGROOT" -cp "$CLASSPATH" $deployerclassname start "$1" sleep 2 } # Tries to stop all User Agents from the specified SDF stop() { java -DMGROOT="$MGROOT" -cp "$CLASSPATH" $deployerclassname stop "$1" sleep 2 } restart() { java -DMGROOT="$MGROOT" -cp "$CLASSPATH" $deployerclassname restart "$1" sleep 2 } # Tests all User Agents from the specified SDF status() { java -DMGROOT="$MGROOT" -cp "$CLASSPATH" $deployerclassname status "$1" sleep 2 } # Tries to clean the environment deleting the temporary files clean() { java -DMGROOT="$MGROOT" -cp "$CLASSPATH" $deployerclassname clean "$1" sleep 2 } printerrdescr() { errcode=$1 echo "${ErrDescr[$errcode]}" } # # # # # # # Main # # # # # # # # Setting macros # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OK=0 NOK=1 # Setting error codes (from 2 to 254) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ERR_STD_MISUSE=2 ERR_BASE=64 ERR_MGROOT_NOT_DEFINED=$[ERR_BASE + 0] ERR_VARS_NOT_DEFINED=$[ERR_BASE + 1] ERR_BAD_JAVA_VERSION=$[ERR_BASE + 2] ERR_BAD_RMI_VERSION=$[ERR_BASE + 3] ERR_JAVA_NOT_FOUND=$[ERR_BASE + 4] ErrDescr=([$ERR_MGROOT_NOT_DEFINED]="Variable MGROOT not defined" [$ERR_VARS_NOT_DEFINED]="BIN and LIB vars not defined" [$ERR_BAD_JAVA_VERSION]="Bad java version" [$ERR_BAD_RMI_VERSION]="Bad RMI version, incompatible with Java Version" [$ERR_JAVA_NOT_FOUND]="Java not found in your path") deployerclassname="org.ourgrid.deployer.Deployer" #----------- MAIN -------------# nargs=$# if [ $nargs -ne 2 ]; then usage fi COMMAND_NAME=$1 SDF=$2 if [ "$COMMAND_NAME" = "init" ] || [ "$COMMAND_NAME" = "start" ] || [ "$COMMAND_NAME" = "stop" ] || [ "$COMMAND_NAME" = "shutdown" ] || [ "$COMMAND_NAME" = "test" ] || [ "$COMMAND_NAME" = "status" ] || [ "$COMMAND_NAME" = "restart" ] || [ "$COMMAND_NAME" = "clean" ] then findmgroot && setenvvars && setclasspath ret=$? else usage fi if [ $ret -ne $OK ]; then errcode=$? printerrdescr $ret exit $errcode fi case "$COMMAND_NAME" in start|init) shift start $SDF ;; stop|shutdown) shift stop $SDF ;; status|test) shift status $SDF ;; restart) shift restart $SDF ;; clean) shift clean $SDF ;; *) usage esac exit $ret