#!/bin/sh
# chkconfig: - 28 72
# description: \
#	Autodir is for creating directories transparently to the applications
#	accessing them  based on available information from
#	sources like password database, group database.
#
#	Autodir depends on linux autofs kernel module to transparently detect
#	directory requests and create them on demand.
#
#	This invocation loads autogroup module which handles group directories
#
# config /etc/sysconfg/autogroup
#
#

CONFIG=/etc/sysconfig/autogroup

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

RETVAL=0

start() {

	# If autofs old module is loaded unload it now
	grep -q -w autofs /proc/modules || \
		/sbin/rmmod autofs 1> /dev/null

	# If module is not loaded load it now
	grep -q autofs4 /proc/modules || \
		/sbin/modprobe -k autofs4 1> /dev/null

	# See if autofs module actually loaded
	grep -q -w autofs4 /proc/modules 
	if [ $? -ne 0 ]
	then
		RETVAL=1;
		return $RETVAL
	fi

	echo -n $"Starting up autogroup : "

	test -r "$CONFIG" && . "$CONFIG"
	daemon /usr/sbin/autodir -d $AUTOGROUP_HOME -m $AUTOGROUP_MODULE \
		${AUTOGROUP_OPTIONS+"-o $AUTOGROUP_OPTIONS"} \
		${AUTOGROUP_TIMEOUT+"-t $AUTOGROUP_TIMEOUT"} \
		${AUTOGROUP_BACKUP+"-b $AUTOGROUP_BACKUP"} \
		${AUTOGROUP_BACKWAIT+"-w $AUTOGROUP_BACKWAIT"} \
		${AUTOGROUP_BACKPRI+"-p $AUTOGROUP_BACKPRI"} \
		${AUTOGROUP_MAXBACK+"-c $AUTOGROUP_MAXBACK"} \
		-l /var/run/autogroup.pid

	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/autogroup
	echo

	return $RETVAL
}

stop() {
	echo -n $"Shutting down autogroup daemon: "
	killproc autogroup
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/autogroup
	echo
	return $RETVAL
}

dostatus() {
	local pid

	pid=`pidfileofproc autogroup`

	if [ -n "$pid" -a -d "/proc/$pid" ]
	then
		echo "autogroup (pid $pid) running..."
		return 0
	else
		echo "auotogroup stopped"
		return 1
	fi
}

restart() {
	stop
	start
}

condrestart() {
	[ -e /var/lock/subsys/autogroup ] && restart || :
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	dostatus
	;;
  restart|reload)
	restart
	;;
  condrestart)
	condrestart
	;;
  *)
	echo $"Usage: autogroup {start|stop|status|restart|reload|condrestart}"
	exit 1
esac

exit $RETVAL

