Project

General

Profile

Download (1.13 KB) Statistics
| Branch: | Tag: | Revision:
1 2e85f5ed Scott Ullrich
#!/bin/sh
2
3
NOTSYNCED="true"
4 0b8e9d38 jim-p
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
/bin/pkill -f ntpdate_sync_once.sh
7 2e85f5ed Scott Ullrich
8 0b8e9d38 jim-p
ATTEMPT=1
9
# Loop until we're synchronized, but for a set number of attempts so we don't get stuck here forever.
10
while [ "$NOTSYNCED" = "true" ] && [ ${ATTEMPT} -le ${MAX_ATTEMPTS} ]; do
11 edf99ce4 jim-p
	# Ensure that ntpd and ntpdate are not running so that the socket we want will be free.
12 0b8e9d38 jim-p
	/usr/bin/killall ntpd 2>/dev/null
13
	/usr/bin/killall ntpdate 2>/dev/null
14 edf99ce4 jim-p
	sleep 1
15 0b8e9d38 jim-p
	/usr/sbin/ntpdate -s -t 5 ${SERVER}
16 2e85f5ed Scott Ullrich
	if [ "$?" = "0" ]; then
17
		NOTSYNCED="false"
18 0b8e9d38 jim-p
	else
19
		sleep 5
20
		ATTEMPT=`expr ${ATTEMPT} + 1`
21 2e85f5ed Scott Ullrich
	fi
22
done
23 edf99ce4 jim-p
24 0b8e9d38 jim-p
if [ "$NOTSYNCED" = "true" ]; then
25
	echo "Giving up on time sync after ${MAX_ATTEMPTS} attempts." | /usr/bin/logger -t ntp;
26 17cf3d17 jim-p
else
27
	echo "Successfully synced time after ${ATTEMPT} attempts." | /usr/bin/logger -t ntp;
28 0b8e9d38 jim-p
fi
29
30
if [ -f /var/etc/ntpd.conf ]; then
31 17cf3d17 jim-p
	echo "Starting NTP Daemon." | /usr/bin/logger -t ntp;
32 a82de14d Jean Cyr
	/usr/local/bin/ntpd -g -c /var/etc/ntpd.conf -p /var/run/ntpd.pid
33 17cf3d17 jim-p
else
34
	echo "NTP configuration file missing, not starting daemon." | /usr/bin/logger -t ntp;
35 0b8e9d38 jim-p
fi