#!/bin/sh # Usage: StartFRM [-d] [-f] [-p] [-t] [-x] # Where: -d turns on debugging # -f forces the start irrespective of the hold file or status, if any. # -p starts only the purge daemon # -t types the start commands and does not execute them # -x starts only the transfer daemon # No option cause everything to be started. # Set defaults #******************************************************************************# #* D e f a u l t s *# #******************************************************************************# TEST= EXITRC=0 FORCE= DOALL=1 ONLYP=0 ONLYX=0 # Source he config file to set additional options # . `dirname $0`/StartXRD.cf #******************************************************************************# #* S u b r o u t i n e s *# #******************************************************************************# Emsg () { echo StartFRM: $1 } isOK () { thePGM=$1 theHLD=$2 if [ -z "$1" -o -z "$2" ]; then REASON="$1 not configured." return 0; fi if [ ! -x $1 ]; then REASON="$1 missing." return 0 fi if [ ! -z "$FORCE" ]; then rm -f $theHLD elif [ -f $theHLD ]; then REASON="$theHLD exists." return 0 fi xPID $thePGM if [ $? -ne 0 ]; then return 0 fi return 1 } xPID () { pidPGM=$1 set -- '' set -- `ps -e -o pid -o args | grep $pidPGM | awk '$0 !~ /grep/ {print $1}'` if [ -z "$1" ]; then return 0 else REASON="already running as pid $1." fi return 1 } Xeq () { $TEST $* & if [ $? -ne 0 ]; then EXITRC=1 fi } #******************************************************************************# #* M a i n *# #******************************************************************************# # Pick up options # XRDPARMS=$* while test -n "$1"; do if [ "$1" = "-d" ]; then set -x OPTS="-d $OPTS" elif [ "$1" = "-f" ]; then FORCE=1 elif [ "$1" = "-p" ]; then DOALL=0 ONLYP=1 elif [ "$1" = "-t" ]; then TEST=echo elif [ "$1" = "-x" ]; then DOALL=0 ONLYX=1 else Emsg "Invalid option - $1." echo 'Usage: StartFRM [-d] [-f] [-p] [-t] [-x]' exit 1 fi shift done # Determine hostname and username # MYHOST=`/bin/hostname` if [ -x /usr/bin/whoami ]; then MYNAME=`/usr/bin/whoami` elif [ -x /usr/ucb/whoami ]; then MYNAME=`/usr/ucb/whoami` else Emsg "Unable to determine username." exit 1 fi # See if we should su to the right user for the frm component. On Solaris # /bin/su doesn't forward the current environment variables and one has to # su to the XRDUSER and run the Start script again. PROGRAM=$XRDCFG/$PROGRAM if [ $MYNAME = root ]; then if [ $XRDUSER != root ]; then $TEST export LD_LIBRARY_PATH $TEST exec su $XRDUSER -c "$PROGRAM $XRDPARMS" fi elif [ $MYNAME != $XRDUSER ]; then Emsg "$MYNAME cannot start $XRDUSER FRM subsystems!" fi # Now set the LD_LIBRARY_PATH variable # if [ -z "$LD_LIBRARY_PATH" ]; then LD_LIBRARY_PATH=$LDLIBPATH else LD_LIBRARY_PATH=$LDLIBPATH:$LD_LIBRARY_PATH fi export LD_LIBRARY_PATH # Now start up the purge daemon # if [ ! -z "$START_PURGE" -a "$DOALL" = "1" -o "$ONLYP" = "1" ]; then isOK $START_PURGE $HFILE_PURGE if [ $? -eq 1 ]; then Emsg "Starting $XRDUSER purge daemon. . ." $TEST cd $HOMED_PURGE Xeq "$START_PURGE $OPTS $PARMS_PURGE" else Emsg "$XRDUSER purge daemon cannot be started on $MYHOST; $REASON" EXITRC=1 fi fi # Now start up the transfer daemon # if [ "$DOALL" = "1" -o "$ONLYX" = "1" ]; then isOK $START_TRANSFER $HFILE_TRANSFER if [ $? -eq 1 ]; then Emsg "Starting $XRDUSER transfer daemon. . ." $TEST cd $HOMED_TRANSFER Xeq "$START_TRANSFER $OPTS $PARMS_TRANSFER" else Emsg "$XRDUSER transfer daemon cannot be started on $MYHOST; $REASON" EXITRC=1 fi fi exit $EXITRC