#!/bin/sh
#
# chkconfig: 345 72 28
# description: Starts arla (free version of AFS client) and mounts /afs
# processname: arlad
# config: /usr/arla/etc/arla.conf
#

BINDIR=/usr/arla/bin
CACHEDIR=/usr/arla/cache

# debug arguments
#ARLAARGS="-n -z --debug=all,-cleaner"
ARLAARGS=

# Source function library.
. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
  start)
	echo -n "Starting arla: "

	if [ ! -d "/afs" ]; then
		echo -n "creating /afs... "
		mkdir /afs
	fi

	if [ ! -c "/dev/xfs0" ]; then
		echo -n "creating /dev/xfs0... "
		mknod /dev/xfs0 c 103 0
	fi

	/sbin/insmod $BINDIR/xfs.o
	/bin/sleep 1
	daemon $BINDIR/arlad $ARLAARGS
	/bin/sleep 1
	/bin/mount -t xfs arla /afs
	echo
	
	;;
  stop)
	echo -n "Shutting down arla: "
	/bin/umount /afs
	killproc arlad
	/sbin/rmmod xfs
	echo
	;;
  status)
	status arlad
	;;
  restart)
	/etc/rc.d/init.d/arla stop
	/etc/rc.d/init.d/arla start
	;;
  reload)
	/etc/rc.d/init.d/arla stop
	# clear the cache -- solves a litany of problems
	/bin/rm -f $CACHEDIR/*
	/etc/rc.d/init.d/arla start
	;;
  *)
	echo "Usage: arla {start|stop|status|restart}"
	exit 1
esac

exit 0
