Blame | Last modification | View Log | RSS feed
#!/bin/bash## chkconfig: - 57 75# description: set the date and time via NTP### BEGIN INIT INFO# Provides: ntpdate# Required-Start: $network $local_fs $remote_fs# Should-Start: $syslog $named# Short-Description: set the date and time via NTP# Description: ntpdate sets the local clock by polling NTP servers### END INIT INFO# Source function library.. /etc/init.d/functions# Source networking configuration.. /etc/sysconfig/networkprog=ntpdatelockfile=/var/lock/subsys/$progntpconf=/etc/ntp.confntpstep=/etc/ntp/step-tickersstart() {[ "$EUID" != "0" ] && exit 4[ "$NETWORKING" = "no" ] && exit 1[ -x /usr/sbin/ntpdate ] || exit 5[ -f /etc/sysconfig/ntpdate ] || exit 6. /etc/sysconfig/ntpdate[ -f $ntpstep ] && tickers=$(sed 's/#.*//' $ntpstep) || tickers=if ! echo "$tickers" | grep -qi '[a-z0-9]' && [ -f $ntpconf ]; then# step-tickers doesn't specify a server,# use servers from ntp.conf insteadtickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf | \egrep -v '127\.127\.[0-9]+\.[0-9]+')fiif ! echo "$tickers" | grep -qi '[a-z0-9]'; thenecho $"NTP server not specified in $ntpstep or $ntpconf"exit 6fiecho -n $"$prog: Synchronizing with time server: "[ -z "$RETRIES" ] && RETRIES=2retry=0while true; do/usr/sbin/ntpdate $OPTIONS $tickers &> /dev/nullRETVAL=$?[ $RETVAL -eq 0 ] || [ $retry -ge "$RETRIES" ] && breaksleep $[10 * (1 << $retry)]retry=$[$retry + 1]done[ $RETVAL -eq 0 ] && success || failureechoif [ $RETVAL -eq 0 ]; thentouch $lockfile[ "$SYNC_HWCLOCK" = "yes" ] && \action $"Syncing hardware clock to system time" \/sbin/hwclock --systohcfireturn $RETVAL}status() {[ -f $lockfile ] || return 3}stop() {[ "$EUID" != "0" ] && exit 4rm -f $lockfile}# See how we were called.case "$1" instart)start;;stop)stop;;status)status;;restart|force-reload)stopstart;;*)echo $"Usage: $0 {start|stop|status|restart|force-reload}"exit 2esac