#!/bin/sh
#
# xntpd         This shell script takes care of starting and stopping
#               xntpd (NTPv3 daemon).
#
# chkconfig: - 55 10
# description: xntpd is the NTPv3 daemon.

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x /usr/sbin/xntpd -a -f /etc/ntp.conf ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
  start)
	# Adjust time to make life easy for xntpd
	if [ -f /etc/ntp/step-tickers ]; then
		echo -n "Syncing time for xntpd. "
		/usr/sbin/ntpdate -s -b -p 8 -u `cat /etc/ntp/step-tickers`
	fi
        # Start daemons.
        echo -n "Starting xntpd: "
        daemon xntpd -A
	RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/xntpd
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down xntpd: "
	killproc xntpd
	RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/xntpd
        ;;
  status)
	status xntpd
	RETVAL=$?
	;;
  restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  *)
        echo "Usage: xntpd {start|stop|restart|status}"
        exit 1
esac

exit $RETVAL
