#!/bin/bash
#
# ntpd         This shell script takes care of starting and stopping
#              ntpd (NTPv4 daemon).
#
# chkconfig: 2345 55 10
# description: ntpd is the NTPv4 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/ntpd -a -f /etc/ntp.conf ] || exit 0

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

exit 0
