NetworkTime   [plain text]


#!/bin/sh

##
# Network Time
##

. /etc/rc.common

StartService ()
{
    if [ "${TIMESYNC:=-YES-}" = "-YES-" ] &&
       ! GetPID ntpd > /dev/null; then

	CheckForNetwork

	if [ -f /var/run/NetworkTime.StartupItem -o "${NETWORKUP}" = "-NO-" ]; then exit; fi
	touch /var/run/NetworkTime.StartupItem


	ConsoleMessage "Starting network time synchronization"

	# Synchronize our clock to the network's time,
	# then fire off ntpd to keep the clock in sync.
	ntpdate -bvs
	ntpd -f /var/run/ntp.drift -p /var/run/ntpd.pid
    fi
}

StopService ()
{
    if pid=$(GetPID ntpd); then
	ConsoleMessage "Stopping network time synchronization"
	kill -TERM "${pid}"
    else
	echo "ntpd is not running."
    fi
}

RestartService () { StopService; StartService; }

RunService "$1"