#!/usr/bin/sh
#set -x
# 
# chkconfig: 345 99 01
# description: Cluster's nodes syncronization startup script  
#
# File : syncfiles 
#

. /etc/rc.d/init.d/functions

stop () {
	PID=`cat $PIDFILE 2>/dev/null`
	PID=`/bin/echo -n $PID`
	RUNNING=`/bin/ps $PID | /bin/grep syncfiles.sh | /usr/bin/wc -l`
	if [ $RUNNING -eq "1" ]; then
		PID=`cat $PIDFILE 2>/dev/null`
		PID=`/bin/echo -n $PID`
		/bin/kill -9 $PID 2>/dev/null
		/bin/kill -9 $PID 2>/dev/null
		/bin/kill -9 $PID 2>/dev/null
	else
		echo "syncfiles.sh currently stopped"
	fi
}

start () {
	PID=`cat $PIDFILE 2>/dev/null`
	PID=`/bin/echo -n $PID`
	RUNNING=`/bin/ps $PID | /bin/grep syncfiles.sh | /usr/bin/wc -l`
	if [ $RUNNING -ne "1" ]; then
		/usr/local/opmon/utils/syncfiles.sh >/dev/null 2>&1 &
	fi
}

source /etc/syncfiles.conf
case "$1" in

	start)
		echo "Starting cluster's syncronization script"
		start
		;;

	stop)
		echo "Stopping cluster's syncronization script"
		stop
		;;
	restart)
		stop
		start
		;;

	status)
		status syncfiles.sh
		exit $?
		;;

	*)
		echo "Usage: syncfiles {start|stop|status|restart}"
		exit 1
		;;

esac

exit 0
  
# End of this script
