Hochschule Augsburg
NTP Service - Realization
Start/Stop Script
#!/bin/sh
#
# /sbin/init.d/xntp
#

case "$1" in
  start)
    if test -x /usr/local/bin/xntpd ; then
      echo "Starting NTP service xntpd."
      /usr/local/bin/tickadj 10000
      /usr/local/bin/ntpdate ntps1-0.uni-erlangen.de
      /usr/local/bin/ntpdate ntps1-1.uni-erlangen.de
      /usr/local/bin/ntpdate ntps1-2.uni-erlangen.de
      /usr/local/bin/xntpd -p /var/run/xntpd.pid 
    fi
    ;;
  stop)
    if [ -f  /var/run/xntpd.pid ] ; then
      echo "Shutting down NTP service."
      kill `cat /var/run/xntpd.pid`
      rm -f /var/run/xntpd.pid
    else 
      echo "xntpd not runnig?"
    fi
    ;;
  restart)
    if [ -f  /var/run/xntpd.pid ] ; then
      echo "Restarting NTP service xntpd."
      kill -1 `cat /var/run/xntpd.pid`
    else
      echo "xntpd not runnig?"
    fi
    if [ -e /var/log/ntp.log.cp ] ; then
      rm -f /var/log/ntp.log.cp
    fi
    cp /var/log/ntp.log /var/log/ntp.log.cp
    tail -q -n 2100 /var/log/ntp.log.cp > /var/log/ntp.log
    rm -f /var/log/ntp.log.cp
    if test -x /usr/local/bin/xntpd ; then
      /usr/local/bin/xntpd -p /var/run/xntpd.pid 
    fi
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

exit 0 
 
This is a template start/stop script suitable for a stand-alone server running S.u.S.E. Linux. You may have to adapt it to your environment. Check the path to the shell, to the xntp binaries and to the script itself.
Let the daemon process id be stored in a file or use the script 'scripts/xntp' in the distribution for stop and restart. Restarting is needed to force a configuration file reread or to trim a log file.
On a machine with bad internal clock (like most PCs) the system clock tick value has to be trimmed. Provided a tickadj program is installed with xntp, observe the offset value of the running xntpd daemon:
# ntpq -i -n -c pe
It will increase or decrease rapidly if the clock drift is too fast. Call
# tickadj
without parameters to see the default tick value (10000 in many cases). Call tickadj with a slightly different value, e.g.
# tickadj 9999
and watch the reaction of xntpd. Edit the final value which will reduce the clock drift to less than 50 ppm into the start script above.
The threefold call of ntpdate will correct the system clock to a very good value before starting the daemon. The offset to UTC will be less than 10 ms without much delay.
2000-01-31
© B. Erdlenbruch
Legal Information