#!/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 autohome module which handles home directories
#
# config /etc/sysconfg/autohome
#
#

CONFIG=/etc/sysconfig/autohome

# 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 autohome daemon: "

	test -r "$CONFIG" && . "$CONFIG"
	daemon /usr/sbin/autodir -d $AUTOHOME_HOME -m $AUTOHOME_MODULE \
		${AUTOHOME_OPTIONS+"-o $AUTOHOME_OPTIONS"} \
		${AUTOHOME_TIMEOUT+"-t $AUTOHOME_TIMEOUT"} \
		${AUTOHOME_BACKUP+"-b $AUTOHOME_BACKUP"} \
		${AUTOHOME_BACKWAIT+"-w $AUTOHOME_BACKWAIT"} \
		${AUTOHOME_BACKPRI+"-p $AUTOHOME_BACKPRI"} \
		${AUTOHOME_MAXBACK+"-c $AUTOHOME_MAXBACK"} \
		-l /var/run/autohome.pid

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

	return $RETVAL
}

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

dostatus() {
	local pid

	pid=`pidfileofproc autohome`

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

restart() {
	stop
	start
}

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

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

exit $RETVAL

