Project

General

Profile

Download (1.27 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2

    
3
NOTSYNCED="true"
4
MAX_ATTEMPTS=3
5
SERVER=`/bin/cat /cf/conf/config.xml | /usr/bin/grep timeservers | /usr/bin/cut -d">" -f2 | /usr/bin/cut -d"<" -f1`
6
if [ "${SERVER}" = "" ]; then
7
	exit
8
fi
9

    
10
/bin/pkill -f ntpdate_sync_once.sh
11

    
12
ATTEMPT=1
13
# Loop until we're synchronized, but for a set number of attempts so we don't get stuck here forever.
14
while [ "$NOTSYNCED" = "true" ] && [ ${ATTEMPT} -le ${MAX_ATTEMPTS} ]; do
15
	# Ensure that ntpd and ntpdate are not running so that the socket we want will be free.
16
	while [ true ]; do
17
		/usr/bin/killall ntpdate 2>/dev/null
18
		/bin/pgrep ntpd
19
		if [ $? -eq 0 ]; then
20
			/usr/bin/killall ntpd 2>/dev/null
21
		else
22
			break
23
		fi
24
	done
25
	sleep 1
26
	/usr/local/sbin/ntpdate -s -t 5 ${SERVER}
27
	if [ "$?" = "0" ]; then
28
		NOTSYNCED="false"
29
	else
30
		sleep 5
31
		ATTEMPT=`expr ${ATTEMPT} + 1`
32
	fi
33
done
34

    
35
if [ "$NOTSYNCED" = "true" ]; then
36
	echo "Giving up on time sync after ${MAX_ATTEMPTS} attempts." | /usr/bin/logger -t ntp;
37
else
38
	echo "Successfully synced time after ${ATTEMPT} attempts." | /usr/bin/logger -t ntp;
39
fi
40

    
41
if [ -f /var/etc/ntpd.conf ]; then
42
	echo "Starting NTP Daemon." | /usr/bin/logger -t ntp;
43
	/usr/local/sbin/ntpd -g -c /var/etc/ntpd.conf -p /var/run/ntpd.pid
44
else
45
	echo "NTP configuration file missing, not starting daemon." | /usr/bin/logger -t ntp;
46
fi
(3-3/36)