Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > e13bdbccf28aef9f5083a287bdaf7b69 > files > 36

openafs.SLx-1.4.3-0.rc2.36.src.rpm

#! /bin/sh
#
# afs	Start/Stop the OpenAFS client
# 
# chkconfig: 345 60 20
# description:  OpenAFS is a distributed filesystem.

. /etc/rc.d/init.d/functions

SYSCNF=/etc/sysconfig/afs
[ -f $SYSCNF ] && . $SYSCNF

CACHEINFO=${CACHEINFO:-/usr/vice/etc/cacheinfo}
CACHE=${CACHEDIR:-/usr/vice/cache}
AFS=${AFSDIR:-/afs}

# is_on returns 1 if value of arg is "on"
is_on() {
    if  test "$1" = "on" ; then return 0
    else return 1
    fi
}

runcmd() {
    echo -n "$1 "
    shift
    if [ "$BOOTUP" = "color" ]; then
	$* && echo_success || echo_failure
    else
	$*
    fi
    echo
}

on_network() {
    ADDRS=`LANG=C ifconfig -a | grep 'inet addr' | grep -v 127.0.0.1 | wc -l`
    if [ "$ADDRS" = "" ]; then
	echo afs: No interfaces with IP address 1>&2
	return 1
    elif [ $ADDRS = 0 ]; then
	echo afs: No interfaces with IP address 1>&2
	return 1
    fi
    #*******************************************
    # Begin of modifications done by Troy Dawson
    #*******************************************	
    FOUNDSERVER="no"
    FINISHED="no"
    cat /usr/vice/etc/CellServDB | {
	while [ "$FINISHED" = "no" ] 
	  do
	  read line || break;
	  CHAR="$(echo $line | cut -c1)"
	  if [ "$CHAR" = ">" ] ; then
	      if [ "$FOUNDSERVER" = "yes" ] ; then
		  FINISHED="yes"
	      else
		  LINECELL="$(echo $line | cut -d' ' -f1 | cut -d'>' -f2)"
		  if [ "$CELL" = "$LINECELL" ] ; then
		      FOUNDSERVER="yes"
		  fi
	      fi
	  else
	      if [ "$FOUNDSERVER" = "yes" ] ; then
		  if [ "$line" = "" ] ; then
		      FINISHED="yes"
		  else
		      SERVER="$(echo $line | cut -d' ' -f1)"
		      /usr/sbin/rxdebug -servers $SERVER -port 7002 2>&1 > /dev/null
		      if [ $? -eq 0 ] ; then
			  return 0
		      fi
		      echo "afs: Unable to reach $SERVER ..." 1>&2
		  fi
	      fi
	  fi
	done
	echo afs: Unable to reach AFS servers. Not starting. 1>&2
	return 1
    }
    #*******************************************
    # End of modifications done by Troy Dawson
    #*******************************************    
    return 0
}

generate_cacheinfo() {
    if [ "$CACHESIZE" = "AUTOMATIC" ]; then
	LINE=`df -Pk $CACHE | tail -1`
	PART=`echo $LINE | awk '{ if ( ($NF != "/usr")  && ($NF != "/") ) print $NF; else print "NONE";}'`
	if [ "$PART" = "NONE" ]; then
	    echo "$CACHE or /usr/vice is not a separate partition" 1>&2
	    echo "you have to change the cachesize in $SYSCNF by hand" 1>&2
	    echo "AFS will be started with the default cache size of 100 MB." 1>&2
	    CACHESIZE=100000
	else
	    PARTSIZE=`echo $LINE | awk '{print $2}'`
	    if grep -q "$CACHE ext3" /proc/mounts ; then
		PARTSIZE=`expr $PARTSIZE - 32768`
	    fi
	    CACHESIZE=`echo $PARTSIZE | awk '{printf "%d",int(($1*.7)/1000)*1000}'`
	fi
    fi
    if [ "x$CACHESIZE" != "x" ]; then
	echo $AFS:$CACHE:$CACHESIZE >$CACHEINFO
	chmod 0644 $CACHEINFO
    else
	CACHESIZE=`awk -F: '{print $3}' < $CACHEINFO`
    fi
}

choose_afsdoptions() {
    # autotuning in afsd should eventually be used instead;
    # alas, it is still broken at least on x86_64 in 1.4.2

    if [ -z "$OPTIONS" -o "$OPTIONS" = "AUTOMATIC" ]; then
        if [ $CACHESIZE -lt 131072 ]; then
            OPTIONS=$SMALL
        elif [ $CACHESIZE -lt 524288 ]; then
            OPTIONS=$MEDIUM
        elif [ $CACHESIZE -lt 1048576 ]; then
            OPTIONS=$LARGE
        elif [ $CACHESIZE -lt 2097152 ]; then
            OPTIONS=$XLARGE
        else
            OPTIONS=$XXLARGE
        fi
    fi

    AFSD_OPTIONS="$OPTIONS $VERBOSE"
    if is_on $ENABLE_AFSDB; then
	AFSD_OPTIONS="$AFSD_OPTIONS -afsdb"
    fi
    if is_on $ENABLE_DYNROOT; then
	AFSD_OPTIONS="$AFSD_OPTIONS -dynroot"
    fi
    if is_on $ENABLE_FAKESTAT; then
	AFSD_OPTIONS="$AFSD_OPTIONS -fakestat"
    fi
    if is_on $ENABLE_SETTIME; then
	AFSD_OPTIONS="$AFSD_OPTIONS -settime"
    fi
}

check_thiscell() {
    CELL=
    if [ -s /usr/vice/etc/ThisCell ] ; then
	CELL="$(cat /usr/vice/etc/ThisCell)"
	if [ -n "$CELL" ]; then
	    grep -w -q -s ">$CELL" /usr/vice/etc/CellServDB
	    if [ $? -ne 0 ] ; then
		echo afs: $CELL from ThisCell is not in CellServDB.  Not starting. 1>&2
		return 1
	    fi
	    return 0
	fi
    fi
    CELL=`dnsdomainname`;
    if [ $? -ne 0 -o -z "$CELL" ] ; then
	echo afs: No cell defined. Trying to figure it out failed. Not starting. 1>&2
	return 1
    fi
    grep -w -q -s ">$CELL" /usr/vice/etc/CellServDB
    if [ $? -ne 0 ] ; then
	echo afs: No cell defined. Trying to figure it out failed. Not starting. 1>&2
	return 1
    fi
    echo "$CELL" > /usr/vice/etc/ThisCell && chmod 0644 /usr/vice/etc/ThisCell
    if [ $? -ne 0 ] ; then
	echo afs: No cell defined. Trying to configure "$CELL" failed. Not starting. 1>&2
	return 1
    fi
    echo afs: Warning: No cell was defined. Autoconfigured "$CELL". 1>&2
}

rhstatus() {
    status afsd
}

case "$1" in 
    start)
	if [ ! -f /var/lock/subsys/afs ]; then
	    echo "Starting AFS client..... "

	    # Start AFS client
	    generate_cacheinfo
	    choose_afsdoptions
	    check_thiscell || exit 1
	    on_network || exit 1

  	    # Load kernel extensions
	    if ! /sbin/modprobe libafs ; then
		echo Failed to load AFS client, not starting AFS services. 1>&2
		exit 1
	    fi

	    /usr/vice/etc/afsd ${AFSD_OPTIONS}
	    touch /var/lock/subsys/afs
	    $AFS_POST_INIT
	fi
	;;

  stop)
    if [ -f /var/lock/subsys/afs ]; then
	# Stop AFS
	echo "Stopping AFS client..... "

	if [ -x /usr/vice/etc/killafs ] ; then
	    runcmd "Sending all processes using /afs the TERM signal ..." /usr/vice/etc/killafs TERM
	    runcmd "Sending all processes using /afs the KILL signal ..." /usr/vice/etc/killafs KILL
	fi
	umount /afs
	/sbin/modprobe -r libafs

	rm -f /var/lock/subsys/afs
    fi
	;;

  restart)
	# Restart AFS
	$0 stop
	$0 start
	;;

  status)
        rhstatus
        ;;

  condrestart)
        [ -f /var/lock/subsys/afs ] && restart || :
        ;;
  *)
	echo Usage: 'afs <start|stop|status|restart|condrestart>'

esac

exit 0

action fool the Red Hat initscripts