#!/bin/sh

. /etc/image_features
. /etc/sysconfig/rc.conf
. /etc/sysconfig/network.conf
. /bin/network-functions
rsync_port=873
. /etc/fiad-conf/syncd.conf

PIDFILE=/var/run/rsyncd.pid
SERVICE=rsyncd
PROCESS_NAME=rsync

do_start ()
{
	if ! ServiceCheckRunning1 ; then
		return $?
	fi

	/etc/init.d/softdogd wait
	if [ "$KEEPALIVED_METHOD" != "true" ] ; then
		rsync_port=873
	fi

	/bin/setsid /bin/$PROCESS_NAME --daemon --ipv4 --port=$rsync_port

	ServiceCheckRunning2

	return
}

do_stop ()
{
	/etc/init.d/softdogd wait

	ServiceStop

	return $?
}

do_status ()
{
	if [ "$START_KEEPALIVED" != "true" ] ; then
		return 0
	fi
	if [ -f /tmp/backupMode ] ; then
		return 0
	fi

	ServiceStatus

	return $?
}

case "$1" in
	start)
		do_start
		;;
	stop)
		do_stop
		;;
	status)
		do_status
		;;
	restart)
		do_stop
		/bin/sleep 2
		do_start
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
esac

exit $?
