Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 1
#!/bin/bash
2
#
3
# chkconfig: - 57 75
4
# description: set the date and time via NTP
5
 
6
### BEGIN INIT INFO
7
# Provides: ntpdate
8
# Required-Start: $network $local_fs $remote_fs
9
# Should-Start: $syslog $named
10
# Short-Description: set the date and time via NTP
11
# Description: ntpdate sets the local clock by polling NTP servers
12
### END INIT INFO
13
 
14
# Source function library.
15
. /etc/init.d/functions
16
 
17
# Source networking configuration.
18
. /etc/sysconfig/network
19
 
20
prog=ntpdate
21
lockfile=/var/lock/subsys/$prog
22
ntpconf=/etc/ntp.conf
23
ntpstep=/etc/ntp/step-tickers
24
 
25
start() {
26
	[ "$EUID" != "0" ] && exit 4
27
	[ "$NETWORKING" = "no" ] && exit 1
28
	[ -x /usr/sbin/ntpdate ] || exit 5
29
	[ -f /etc/sysconfig/ntpdate ] || exit 6
30
	. /etc/sysconfig/ntpdate
31
 
32
	[ -f $ntpstep ] && tickers=$(sed 's/#.*//' $ntpstep) || tickers=
33
 
34
	if ! echo "$tickers" | grep -qi '[a-z0-9]' && [ -f $ntpconf ]; then
35
	    # step-tickers doesn't specify a server,
36
	    # use servers from ntp.conf instead
37
	    tickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf | \
38
		egrep -v '127\.127\.[0-9]+\.[0-9]+')
39
	fi
40
 
41
	if ! echo "$tickers" | grep -qi '[a-z0-9]'; then
42
	    echo $"NTP server not specified in $ntpstep or $ntpconf"
43
	    exit 6
44
	fi
45
 
46
	echo -n $"$prog: Synchronizing with time server: "
47
 
48
	[ -z "$RETRIES" ] && RETRIES=2
49
	retry=0
50
	while true; do
51
		/usr/sbin/ntpdate $OPTIONS $tickers &> /dev/null
52
		RETVAL=$?
53
		[ $RETVAL -eq 0 ] || [ $retry -ge "$RETRIES" ] && break
54
		sleep $[10 * (1 << $retry)]
55
		retry=$[$retry + 1]
56
	done
57
 
58
	[ $RETVAL -eq 0 ] && success || failure
59
	echo
60
	if [ $RETVAL -eq 0 ]; then
61
	    touch $lockfile
62
	    [ "$SYNC_HWCLOCK" = "yes" ] && \
63
		action $"Syncing hardware clock to system time" \
64
		    /sbin/hwclock --systohc
65
	fi
66
	return $RETVAL
67
}
68
 
69
status() {
70
	[ -f $lockfile ] || return 3
71
}
72
 
73
stop() {
74
	[ "$EUID" != "0" ] && exit 4
75
	rm -f $lockfile
76
}
77
 
78
# See how we were called.
79
case "$1" in
80
  start)
81
	start
82
	;;
83
  stop)
84
	stop
85
	;;
86
  status)
87
	status
88
	;;
89
  restart|force-reload)
90
	stop
91
	start
92
	;;
93
  *)
94
	echo $"Usage: $0 {start|stop|status|restart|force-reload}"
95
	exit 2
96
esac