cvsdist 42bb2e1
#!/bin/bash
cvsdist 576c192
#
cvsdist 576c192
# ntpd		This shell script takes care of starting and stopping
cvsdist 576c192
#		ntpd (NTPv4 daemon).
cvsdist 576c192
#
cvsdist 4ea82e7
# chkconfig: - 58 74
cvsdist 42bb2e1
# description: ntpd is the NTPv4 daemon. \
cvsdist 42bb2e1
# The Network Time Protocol (NTP) is used to synchronize the time of \
cvsdist 42bb2e1
# a computer client or server to another server or reference time source, \
cvsdist 42bb2e1
# such as a radio or satellite receiver or modem.
cvsdist 576c192
66d2997
### BEGIN INIT INFO
66d2997
# Provides: ntpd
66d2997
# Required-Start: $network $local_fs $remote_fs
66d2997
# Required-Stop: $network $local_fs $remote_fs
66d2997
# Should-Start: $syslog $named
66d2997
# Should-Stop: $syslog $named
66d2997
# Short-Description: start and stop ntpd
66d2997
# Description: ntpd is the NTPv4 daemon. The Network Time Protocol (NTP)
66d2997
#              is used to synchronize the time of a computer client or
66d2997
#              server to another server or reference time source, such
66d2997
#              as a radio or satellite receiver or modem.
66d2997
### END INIT INFO
66d2997
cvsdist 576c192
# Source function library.
cvsdist 576c192
. /etc/init.d/functions
cvsdist 576c192
cvsdist 576c192
# Source networking configuration.
cvsdist 576c192
. /etc/sysconfig/network
cvsdist 576c192
cvsdist b752f8e
if [ -f /etc/sysconfig/ntpd ];then
cvsdist b752f8e
        . /etc/sysconfig/ntpd
cvsdist b752f8e
fi
cvsdist b752f8e
66d2997
prog=ntpd
66d2997
lockfile=/var/lock/subsys/$prog
cvsdist a2cf45e
ntpconf=/etc/ntp.conf
cvsdist a2cf45e
ntpstep=/etc/ntp/step-tickers
cvsdist a2cf45e
53073da
sync_hwclock() {
53073da
	ARC=0
53073da
	SRM=0
53073da
	UTC=0
53073da
53073da
	if [ -f /etc/sysconfig/clock ]; then
53073da
	   . /etc/sysconfig/clock
53073da
53073da
	   # convert old style clock config to new values
53073da
	   if [ "${CLOCKMODE}" = "GMT" ]; then
53073da
	      UTC=true
53073da
	   elif [ "${CLOCKMODE}" = "ARC" ]; then
53073da
	      ARC=true
53073da
	   fi
53073da
	fi
53073da
53073da
	CLOCKFLAGS="$CLOCKFLAGS --systohc"
53073da
53073da
	case "$UTC" in
53073da
	    yes|true)	CLOCKFLAGS="$CLOCKFLAGS --utc";;
53073da
	    no|false)	CLOCKFLAGS="$CLOCKFLAGS --localtime";;
53073da
	esac
53073da
	case "$ARC" in
53073da
	    yes|true)	CLOCKFLAGS="$CLOCKFLAGS --arc";;
53073da
	esac
53073da
	case "$SRM" in
53073da
	    yes|true)	CLOCKFLAGS="$CLOCKFLAGS --srm";;
53073da
	esac
53073da
53073da
	action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
53073da
}
53073da
cvsdist 28b0939
readconf() {
cvsdist 42bb2e1
	dostep=''
cvsdist bf6954f
	dropstr=''
8a7ee9c
	hasg=''
e491b03
	OPTIND=1
8a7ee9c
	while getopts ":46aAbc:dD:f:gi:I:k:l:LmnN:p:P:qr:s:t:u:U:v:V:x" args $OPTIONS;
cvsdist 42bb2e1
	do 
e491b03
	  case "$args" in
e491b03
	    x) dostep=yes;;
e491b03
	    c) ntpconf="$OPTARG";;
e491b03
	    u) dropstr="-U $(echo $OPTARG | sed 's/:.*//')";;
8a7ee9c
	    g) hasg=yes;;
e491b03
	  esac
cvsdist 42bb2e1
	done
cvsdist 42bb2e1
e491b03
	tickers=''
e491b03
	if [ -s "$ntpstep" ]; then
e491b03
	    tickers=$(sed 's/#.*//' $ntpstep)
e491b03
	    echo "$tickers" | grep -qi '[a-z0-9]' && dostep=yes || tickers=''
e491b03
	fi
e491b03
	if [ -n "$dostep" -a -z "$tickers" ]; then
e491b03
	    # -x option is used, but step-tickers doesn't exist or contain
e491b03
	    # anything useful, use servers from ntp.conf instead
e491b03
	    tickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf | \
8a7ee9c
	        egrep -v '127\.127\.[0-9]+\.[0-9]+')
e491b03
	fi
cvsdist 28b0939
}
cvsdist 47c2172
cvsdist 28b0939
start() {
1180ab4
	# Check that networking is up.
1180ab4
	[ "$NETWORKING" = "no" ] && exit 1
1180ab4
66d2997
	[ -x /usr/sbin/ntpd ] || exit 5
66d2997
cvsdist 28b0939
	readconf;
cvsdist 42bb2e1
e491b03
	if [ -n "$dostep" ]; then
cvsdist 42bb2e1
	    echo -n $"$prog: Synchronizing with time server: "
34d5908
	    /usr/sbin/ntpdate $dropstr -s -b $NTPDATE_OPTIONS $tickers &>/dev/null
cvsdist 42bb2e1
	    RETVAL=$?
cvsdist 42bb2e1
	    [ $RETVAL -eq 0 ] && success || failure
cvsdist 42bb2e1
	    echo
53073da
	    if [ $RETVAL -eq 0 ]; then
53073da
	        [ "$SYNC_HWCLOCK" = "yes" ] && sync_hwclock
8a7ee9c
	    elif [ -z "$hasg" ]; then
53073da
	        OPTIONS="$OPTIONS -g"
cvsdist 42bb2e1
	    fi
8a7ee9c
	elif [ -z "$hasg" ]; then
cvsdist 42bb2e1
	    # -g can replace the grep for time servers
cvsdist 42bb2e1
	    # as it permits ntpd to violate its 1000s limit once.
cvsdist 42bb2e1
	    OPTIONS="$OPTIONS -g"
cvsdist 576c192
	fi
cvsdist 576c192
        # Start daemons.
cvsdist 576c192
        echo -n $"Starting $prog: "
66d2997
        daemon $prog $OPTIONS
cvsdist 576c192
	RETVAL=$?
cvsdist 576c192
        echo
66d2997
	[ $RETVAL -eq 0 ] && touch $lockfile
cvsdist 576c192
	return $RETVAL
cvsdist 576c192
}
cvsdist 576c192
cvsdist 576c192
stop() {
cvsdist 576c192
        echo -n $"Shutting down $prog: "
66d2997
	killproc $prog
cvsdist 576c192
	RETVAL=$?
cvsdist 576c192
        echo
66d2997
	[ $RETVAL -eq 0 ] && rm -f $lockfile
cvsdist 576c192
	return $RETVAL
cvsdist 576c192
}
cvsdist 576c192
cvsdist 576c192
# See how we were called.
cvsdist 576c192
case "$1" in
cvsdist 576c192
  start)
cvsdist 576c192
	start
66d2997
	;;
cvsdist 576c192
  stop)
cvsdist 576c192
	stop
66d2997
	;;
cvsdist 576c192
  status)
66d2997
	status $prog
cvsdist 576c192
	;;
66d2997
  restart|force-reload)
cvsdist 576c192
	stop
cvsdist 576c192
	start
cvsdist 576c192
	;;
66d2997
  try-restart|condrestart)
66d2997
	if status $prog > /dev/null; then
cvsdist 576c192
	    stop
cvsdist 576c192
	    start
cvsdist 576c192
	fi
cvsdist 576c192
	;;
66d2997
  reload)
66d2997
	exit 3
66d2997
	;;
cvsdist 576c192
  *)
66d2997
	echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
66d2997
	exit 2
cvsdist 576c192
esac