#!/bin/sh

# Bring up/down ntpd

. /etc/sysconfig/rc.conf
. /bin/network-functions
. /etc/image_features

SETSID=/usr/bin/setsid
PIDFILE=/var/run/sntp-daemon-client.pid
SERVICE=ntp
PROCESS_NAME=sntp-daemon

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

	/etc/init.d/softdogd wait

#if [ "$FEATURE_FIREWALL" = "1" ] ; then
#	/bin/firewall_blocking system add ntp > /dev/null 2>&1
#fi
	/bin/sleep 1
	$SETSID /bin/$PROCESS_NAME -c -r -i $TIME_UPDATE -p $PIDFILE
	ServiceCheckRunning2

	return $?
}

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

	/etc/init.d/softdogd wait

#if [ "$FEATURE_FIREWALL" = "1" ] ; then
#	/bin/firewall_blocking system add ntp > /dev/null 2>&1
#fi
	$SETSID /bin/$PROCESS_NAME -r -i $TIME_UPDATE -p $PIDFILE
	ServiceCheckRunning2

	return $?
}

do_stop ()
{
	/etc/init.d/softdogd wait
#if [ "$FEATURE_FIREWALL" = "1" ] ; then
#	/bin/firewall system del ntp > /dev/null 2>&1
#fi
	ServiceStop

	return $?
}

do_status ()
{
	ServiceStatus

	return $?
}

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

exit $?
