#!/bin/sh
#
# Version: 1.2
#
# chkconfig: - 72 28
# description: Runs the automount daemon that mounts devices and NFS hosts \
#	       on demand.
# processname: amd
# config: /etc/amd.conf
#

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

. /etc/sysconfig/amd

# we require the /etc/amd.conf file
[ -f /etc/amd.conf ] || exit 0

# See how we were called.
case "$1" in
  start)
	echo -n "Starting amd: "
	touch /var/lock/subsys/amd
	daemon /usr/sbin/amd -F /etc/amd.conf $AMDOPTS
	echo
	
	;;
  stop)
	echo -n "Shutting down amd: "
	delay=3
	count=5
	i=1
	is_down="nope"
	while [ $i != $count ]; do
	    # run amq
	    /usr/sbin/amq > /dev/null 2>&1
	    if [ $? != 0 ] ; then
		# amd is down
		is_down=""
		break
	    fi
	    sleep $delay
	    i=`expr $i + 1`
	done
	if [ -n "$is_down" ] ; then
	    killproc amd
	fi
	rm -f /var/lock/subsys/amd
	echo
	;;
  status)
	status amd
	;;
  restart)
	$0 stop
	$0 start
	;;
  reload)
	killall -HUP amd
	;;
  *)
	echo "Usage: amd {start|stop|status|restart|reload}"
	exit 1
esac

exit 0

