#!/bin/bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Package: OurGrid 3.3.1 # # Description: working with User Agent # # Copyright (c) 2002-2006 Universidade Federal de Campina Grande # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #!/bin/sh # Setting macros # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OK=0 NOK=1 # Setting error codes (from 2 to 254) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ERR_BASE=64 ERR_STD_MISUSE=$[ERR_BASE + 0] ERR_MGROOT_NOT_DEFINED=$[ERR_BASE + 1] ERR_VARS_NOT_DEFINED=$[ERR_BASE + 2] ERR_JAVAOPTIONS_NOT_DEFINED=$[ERR_BASE + 3] ERR_CLASSPATH_NOT_DEFINED=$[ERR_BASE + 6] ERR_JAVA_NOT_FOUND=$[ERR_BASE + 7] ERR_ON_UA_PROPERTIES=$[ERR_BASE + 8] ErrDescr=([$ERR_STD_MISUSE]="Syntax error" [$ERR_MGROOT_NOT_DEFINED]="Variable MGROOT not defined" [$ERR_VARS_NOT_DEFINED]="BIN and LIB vars not defined" [$ERR_JAVAOPTIONS_NOT_DEFINED]="Java options not defined" [$ERR_CLASSPATH_NOT_DEFINED]="CLASSPATH variable not defined" [$ERR_JAVA_NOT_FOUND]="Java not found in your path") # Find UAROOT: # $0 is the executable $UAROOT/useragent or a link to it # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - finduaroot(){ 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"` UAROOT=`cd "$PRGDIR/" ; pwd` if [ -z "$UAROOT" ]; then echo "UAROOT NOT DEFINED" return $NOK else return $OK fi } usage(){ if [ $# -eq 0 ]; then echo "Usage: useragent command [command-options-and-arguments]" echo " where command is start, stop, status or restart" echo " where command-options-and-arguments depend on the specific command" echo echo "For OurGrid updates and additional information, see the " echo "OurGrid Project home page at http://www.ourgrid.org/ " else case "$1" in start) echo "help $1" ;; stop) echo "help $1" ;; status) echo "help $1" ;; restart) echo "help $1" ;; *) echo "not implemented" esac fi exit $ERR_STD_MISUSE } usage_commands(){ UNK_CMD=$1 echo "useragent: Unknown command '$UNK_CMD'" echo echo "USERAGENT commands are:" echo " start Start OurGrid user agent" echo " restart Stop and start OurGrid user agent" echo " stop Stop OurGrid user agent" echo " status Verify OurGrid user agent status" } execute() { command=$1 uacmdname="org.ourgrid.gridmachine.useragent.ui.CommandManager" if [ -z "$INVOKED_BY_UAADMIN" ]; then java -Xmx256m -cp $CLASSPATH $uacmdname $command & else # This is necessary for ssh not hang during uaadmin # execution java -Xmx256m -cp $CLASSPATH $uacmdname $command < /dev/null >& /dev/null & fi sleep 2 } printerrdescr() { errcode=$1 echo "${ErrDescr[$errcode]}" } # --------- Main -------- # GM=`hostname -f` nargs=$# if [ $nargs -eq 2 ]; then INVOKED_BY_UAADMIN=1 else if [ $nargs -eq 0 ] || [ $nargs -gt 2 ]; then usage fi fi COMMAND_NAME=$1 if [ "$COMMAND_NAME" = "start" ] || [ "$COMMAND_NAME" = "stop" ] || [ "$COMMAND_NAME" = "status" ] || [ "$COMMAND_NAME" = "restart" ]; then finduaroot cd $UAROOT export CLASSPATH=".:useragent.jar:aspectjrt.jar:log4j.jar" ret=$? if [ $ret -ne $OK ]; then errcode=$ret printerrdescr $errcode exit $errcode fi else usage fi case "$COMMAND_NAME" in start) execute start ;; status) execute status ;; stop) execute stop ;; restart) execute stop execute start ;; *) usage esac exit $ret