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
|
/bin/pkill -f ntpdate_sync_once.sh
|
7
|
|
8
|
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
|
# Ensure that ntpd and ntpdate are not running so that the socket we want will be free.
|
12
|
/usr/bin/killall ntpd 2>/dev/null
|
13
|
/usr/bin/killall ntpdate 2>/dev/null
|
14
|
sleep 1
|
15
|
/usr/sbin/ntpdate -s -t 5 ${SERVER}
|
16
|
if [ "$?" = "0" ]; then
|
17
|
NOTSYNCED="false"
|
18
|
else
|
19
|
sleep 5
|
20
|
ATTEMPT=`expr ${ATTEMPT} + 1`
|
21
|
fi
|
22
|
done
|
23
|
|
24
|
if [ "$NOTSYNCED" = "true" ]; then
|
25
|
echo "Giving up on time sync after ${MAX_ATTEMPTS} attempts." | /usr/bin/logger -t ntp;
|
26
|
else
|
27
|
echo "Successfully synced time after ${ATTEMPT} attempts." | /usr/bin/logger -t ntp;
|
28
|
fi
|
29
|
|
30
|
if [ -f /var/etc/ntpd.conf ]; then
|
31
|
echo "Starting NTP Daemon." | /usr/bin/logger -t ntp;
|
32
|
/usr/local/bin/ntpd -g -c /var/etc/ntpd.conf
|
33
|
else
|
34
|
echo "NTP configuration file missing, not starting daemon." | /usr/bin/logger -t ntp;
|
35
|
fi
|