NTP fail to sync if time sync is not performed

Time sensitive services may not be able to startup and be synchronized,
specifically when deployed on multiple nodes, when the hardware clock
of the booting system is not explicitly synchronized before attempting
to start the services. With this, NTP itself may not be able to
synchronize and start operating if the clock is skewed too much from
the clock source(s), or if one clock source is out of sync itself.

This change move the ntp stand-up earlier in setup so that time of any
system is controlled befor time sensitive services startup. For example
the database on controller nodes. The change also set the clock to the
time of the given ntp server forcefully and updates the Hardware clock.
It also fixes the invalid ntp.conf file.

Closes-Bug: 1408379
Relates-To: I56a03dc0a899a8c515f2a05d678d7e80e9b7b93c
Change-Id: Ib9931b84925d9ceb32f18e9adc5be64402fbf61e
This commit is contained in:
Nicholas Randon 2015-01-07 09:33:15 +00:00
parent 4f52bce01c
commit b8266fa7ec
4 changed files with 35 additions and 4 deletions

View File

@ -14,11 +14,19 @@ filegen clockstats file clockstats type day enable
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
# Local users get more
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
# Remote NTP server(s) to synchronize with.
{{#ntp.servers}}
{{#server}}
server {{server}}
{{#fudge}}fudge {{server}} {{fudge}}{{/fudge}}
{{/server}}
{{/ntp.servers}}
# Specify the internal hardware clock as a reference clock.
# Set a high stratum so this is only used if all external clocks fail.
# This will mitigate skew until external clocks return to service.
server 127.127.1.0 # local clock address
fudge 127.127.1.0 stratum 10

View File

@ -0,0 +1,22 @@
#!/bin/bash
set -eu
set -o pipefail
# NTP server to sync with.
NTP_SERVER="$(os-apply-config --key 'ntp.servers.0.server' --type raw --key-default '')"
SERVICE_NAME="$(svc-map ntpd)"
if [ -n "${NTP_SERVER}" ]; then
ntpdate -q "${NTP_SERVER}" ||
{ echo "ERROR: ntpdate cannot connect to: ${NTP_SERVER}"; exit 1; }
# Check ntpd is running, if it is stop the service.
service "${SERVICE_NAME}" status && service "${SERVICE_NAME}" stop
# Set the system clock to the value of the NTP clock.
# Note: This will not sanity check the ntp server like ntpd.
ntpdate -b "${NTP_SERVER}"
hwclock --systohc # Re-align the H/W clock. (incase of power loss)
service "${SERVICE_NAME}" start
fi

View File

@ -1,2 +0,0 @@
#!/bin/sh
service ntp restart || service ntpd restart

3
elements/ntp/svc-map Normal file
View File

@ -0,0 +1,3 @@
ntpd:
default: ntp
redhat: ntpd