#!/bin/bash
#
# fam_mirrord   Starts fam_mirrord.
#
#
# chkconfig: 2345 12 88
# description: fam_mirrord is a daemon that runs in the background and \
# consults FAM for modified/created/deleted files in the system and \
# copies them to the configured mirror server.

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

[ -f /bin/fam_mirrord ] || exit 0

# Source config
if [ -f /etc/sysconfig/fam_mirrord ] ; then
	. /etc/sysconfig/fam_mirrord
else
	DIRECTORIES="/home /var/www"
fi

RETVAL=0

umask 077

start() {
 	echo -n $"Starting Mirror Daemon: "
	daemon fam_mirrord $DIRECTORIES
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/fam_mirrord
	return $RETVAL
}	
stop() {
	echo -n $"Shutting down Mirror Daemon: "
	if [ -f /var/run/fam_mirrord.pid ] ; then
		PID=`/bin/cat /var/run/fam_mirrord.pid`
	else
		PID=`ps gx|grep "/bin/fam_mirrord"|awk {'print $1'}`
	fi
	if [ z$PID == "z" ] ; then
		echo "-- Nor Running --"
		exit 0	
	fi
	if [ z$PID != "z" ] ; then
		RETVALK=`kill -9 $PID`
		RMLOCK=`rm -f /var/lock/subsys/fam_mirrord`
		RMPID=`rm -f /var/run/fam_mirrord.pid`
		DONE=1
	fi
	[ $DONE -eq 1 ] && echo_success
	echo
	return $RETVAL
}
rhstatus() {
	status fam_mirrord 
}
restart() {
	stop
	start
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  status)
  	rhstatus
	;;
  restart|reload)
  	restart
	;;
  condrestart)
  	[ -f /var/lock/subsys/fam_mirror ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart}"
	exit 1
esac

exit $?

