#!/bin/bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Package: OurGrid 3.3.2 # # Description: This shell script takes care of starting the core. # # Copyright (c) 2002-2004 Universidade Federal de Campina Grande # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # 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] # # Usage function to show how to use corepeer. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - usage() { echo "CorePeer: Unknown command." echo echo "Corepeer commands are:" echo " start Starts corepeer on the local machine" echo " stop Stops corepeer on the local machine" echo " status Shows current corepeer status" } # 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(){ 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(){ mypath=. for i in `/bin/ls $LIB/*.jar`; do mypath=$mypath:$i done CLASSPATH=$mypath if [ -z "$CLASSPATH" ]; then echo "ERR_VARS_NOT_DEFINED" return $ERR_CLASSPATH_NOT_DEFINED else return $OK fi } # Set the JAVAOPTION to invoke MyGrid classes # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - setjavaoptions(){ JAVAOPTIONS=" -classpath $CLASSPATH -DMGROOT=$MGROOT -Dsun.net.inetaddr.ttl=0" } # +++++ Start CorePeer start() { java $JAVAOPTIONS $main start & sleep 3 } stop() { java $JAVAOPTIONS $main stop & sleep 3 } status() { java $JAVAOPTIONS $main status exit $? } main="org.ourgrid.corepeer.ui.CommandManager" # Check findmgroot && setenvvars && setclasspath && setjavaoptions case "$1" in start) start ;; stop) stop ;; status) status exit $? ;; *) usage exit 5 ;; esac