#!/bin/bash # # ntpd This shell script takes care of starting and stopping # ntpd (NTPv4 daemon). # # chkconfig: 235 58 74 # description: ntpd is the NTPv4 daemon. \ # The Network Time Protocol (NTP) is used to synchronize the time of \ # a computer client or server to another server or reference time source, \ # such as a radio or satellite receiver or modem. # Source function library. . /etc/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "${NETWORKING}" = "no" ] && exit 0 if [ -f /etc/sysconfig/ntpd ];then . /etc/sysconfig/ntpd fi ntpconf=/etc/ntp.conf ntpstep=/etc/ntp/step-tickers RETVAL=0 PATH=$PATH:/usr/local/bin prog="ntpd" readconf() { # get the servers from step-ticker tickers='' if [ -s "$ntpstep" ]; then tickers=`/bin/sed -e 's/\#.*$//g' $ntpstep` fi [ -x /usr/local/bin/ntpd -a -f $ntpconf ] || exit 0 } start() { readconf; if [ -s "$ntpstep" ]; then echo -n $"$prog: Synchronizing with time server: " ntpdate -s -b $tickers 2>/dev/null >/dev/null RETVAL=$? [ $RETVAL -eq 0 ] && success || failure echo if [ $RETVAL -ne 0 ]; then OPTIONS="$OPTIONS -g" fi else OPTIONS="$OPTIONS -g" fi echo -n $"Starting $prog: " daemon ntpd $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ntpd return $RETVAL } stop() { echo -n $"Shutting down $prog: " killproc ntpd RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ntpd return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status ntpd RETVAL=$? ;; restart|reload) stop start RETVAL=$? ;; condrestart) if [ -f /var/lock/subsys/ntpd ]; then stop start RETVAL=$? fi ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" exit 1 esac exit $RETVAL