#!/bin/bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Package: OurGrid 3.3.1 # # Description: This shell script takes care of starting and # stopping OurGrid Peer. # # Copyright (c) 2002-2006 Universidade Federal de Campina Grande # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # OurGrid Version # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OGVERSION="3.3.1" # 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] 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 MGROOT: # $0 is the executable $MGROOT/bin/peer 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(){ VAR=$MGROOT/var BIN=$MGROOT/bin LIB=$MGROOT/lib SAMPLE=$MGROOT/sample TEST=$MGROOT/test if [ -z "$VAR" ] || [ -z "$BIN" ] || [ -z "$LIB" ] || [ -z "$SAMPLE" ] || [ -z "$TEST" ]; 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" if [ -z "$CLASSPATH" ]; then return $ERR_CLASSPATH_NOT_DEFINED else return $OK fi } # Set the JAVAOPTION to invoke OurGrid classes # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - setjavaoptions(){ if [ -z ${OGROOT} ]; then JAVAOPTIONS="-DMGROOT=$MGROOT" else JAVAOPTIONS="-DMGROOT=$MGROOT -DOGROOT=$OGROOT" fi } # Start OurGrid Peer # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - pre_peer() { CONFDIR="$MGROOT" if [ -n "$OGROOT" ]; then CONFDIR="$OGROOT" fi mkdir -p "$CONFDIR/log" } ## Start OurGrid Peer GUI ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #gui() { # pre_peer # java -classpath "$CLASSPATH" "$JAVAOPTIONS" "$commandmanager" "$guicommand" & #} # Starts OurGrid Peer # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - start() { pre_peer java -Xms64m -Xmx1024m -classpath "$CLASSPATH" "$JAVAOPTIONS" "$commandmanager" "$startcommand" & sleep 3 } # Stop OurGrid Peer # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - stop() { java -Xms64m -Xmx1024m -classpath "$CLASSPATH" "$JAVAOPTIONS" "$commandmanager" "$stopcommand" } # Show OurGrid Peer Status # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - status() { java -Xms64m -Xmx1024m -classpath "$CLASSPATH" "$JAVAOPTIONS" "$commandmanager" "$statuscommand" exit $? } printerrdescr() { errcode=$1 echo "${ErrDescr[$errcode]}" } usage(){ if [ $# -eq 0 ]; then echo "Usage: peer command [command-options-and-arguments]" echo " where command is start, stop, setgums and status" 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 "Usage: peer start" ;; stop) echo "Usage: peer stop" ;; status) echo "Usage: peer status" ;; setgums) echo "Usage: peer setgums " ;; # gui) echo "Usage: peer gui" # ;; version) echo "OurGrid $OGVERSION - Peer" echo echo "For OurGrid updates and additional information, see the " echo "OurGrid Project home page at http://www.ourgrid.org/ " ;; *) echo "no implemented" esac fi exit $ERR_STD_MISUSE } usage_commands(){ UNK_CMD=$1 echo "peer: Unknown command '$UNK_CMD'" echo echo "OURGRID commands are:" echo " start Starts peer on the local machine" echo " stop Stops peer on the local machine" echo " status Shows current peer status" echo " setgums Sets peers gums" #echo " gui Starts peer gui" exit $ERR_STD_MISUSE } nargs=$# if [ $nargs -eq 0 ]; then COMMAND_NAME="help" fi if [ "$1" = "version" ] || [ "$1" = "-v" ]; then usage version fi if [ "$1" = "start" ] || [ "$1" = "stop" ] || [ "$1" = "status" ] || [ "$1" = "gui" ]; then if [ $nargs -eq 1 ]; then COMMAND_NAME=$1 else usage $1 fi fi if [ "$1" = "setgums" ]; then if [ $nargs -eq 2 ]; then COMMAND_NAME=$1 COMMAND_ARGS=$2 else usage $1 fi fi if [ -z "$COMMAND_NAME" ]; then usage_commands $1 fi # In this point, the user has invoked OurGrid correctly. So, we # have to launch the appropriated behaviour. commandmanager="org.ourgrid.peer.ui.command.CommandManager" startcommand="start" stopcommand="stop" statuscommand="status" setgumscommand="setgums" guicommand="gui" mgname=`basename $0` # Check findmgroot && setenvvars && setclasspath && setjavaoptions ret=$? if [ $ret -eq $OK ]; then case "$COMMAND_NAME" in start) start ;; stop) stop ;; status) status exit $? ;; #gui) # gui # exit $? # ;; setgums) java -Xms64m -Xmx1024m -classpath "$CLASSPATH" "$JAVAOPTIONS" "$commandmanager" "$setgumscommand" "$COMMAND_ARGS" ;; *) usage exit $ret ;; esac else errcode=$ret printerrdescr $errcode exit $errcode fi