#! /bin/sh # # ntpd init.d script for ntpdc from ntp.isc.org #chkconfig: 2345 20 20 # Source function library. . /etc/init.d/functions test -x /usr/sbin/ntpd -a -r /etc/ntp.conf || exit 0 # rcS contains TICKADJ test -r /etc/default/rcS && . /etc/default/rcS # Functions to do individual actions settick(){ # If TICKADJ is set we *must* adjust it before we start, because the # driftfile relies on the correct setting test -n "$TICKADJ" -a -x /usr/sbin/tickadj && { echo -n "Setting tick to $TICKADJ: " /usr/sbin/tickadj "$TICKADJ" echo "done" } } startdaemon(){ # Perform initial ntp time correction if [ -e /etc/ntp_initial.conf ] then echo -n "Performing initial ntp time correction: " # ntpd -q hangs forever if it can't reach a server, so the timeout # command is used to avoid this /usr/bin/timeout 60s /usr/sbin/ntpd -q -g -c /etc/ntp_initial.conf rc=$? if [[ $rc == 0 ]] then echo "done" # Time correction successful. Set hardware clock. echo -n "Setting hardware clock: " /sbin/hwclock -wu if [[ $? == 0 ]] then echo "done" else echo "failed" fi else echo "fail - hardware clock used to set system time" fi fi # We do not use the -g option to start the ntpd. That allows the ntpd to # make large time corrections. Although the man page says this will be # done only once, testing indicates it can happen multiple times or # happen long after the daemon starts, which can break services that # are already running at that time. echo -n "Starting ntpd: " /sbin/start-stop-daemon --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" echo "done" } stopdaemon(){ echo -n "Stopping ntpd: " /sbin/start-stop-daemon --stop -p /var/run/ntp.pid echo "done" # Set the hardware clock on shutdown so the clock will be as accurate as possible # when the system comes back up. echo -n "Setting hardware clock: " /sbin/hwclock -wu if [[ $? == 0 ]] then echo "done" else echo "failed" fi } case "$1" in start) settick startdaemon ;; stop) stopdaemon ;; status) status /usr/sbin/ntpd; exit $? ;; force-reload) stopdaemon settick startdaemon ;; restart) # Don't reset the tick here stopdaemon startdaemon ;; reload) # Must do this by hand, but don't do -g stopdaemon startdaemon ;; *) echo "Usage: ntpd { start | stop | status | restart | reload }" >&2 exit 1 ;; esac exit 0