Periodically sync time if continuous ntpd is unsynchronized (#1611)

When update-clock is run periodically, if ntpd is running continuously,
check whether it is actually in sync, as measured by a reported stratum
of less than 16.

If it's not in sync, run the full manual clock sync algorithm otherwise
used for our periodic-only synchronization.

This should help with hosts that expect to synchronize from an NTP server
on the internet, for example, when they've temporarily lost the internet
connection. Or alternately, if configured to use a mesh-based NTP server
that has disappeared from the mesh.
This commit is contained in:
Brett T. Warden 2024-10-08 21:01:45 -07:00 committed by GitHub
parent e6943bd0d1
commit 65b09ab8b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -41,8 +41,10 @@ exec 2> /dev/null
# If real ntp is running, we don't need to do this
if [ "$(pidof ntpd)" != "" ]; then
echo -n "ntp" > /tmp/timesync
exit 0
if [ -f /var/state/ntp-stratum ] && [ $(cat /var/state/ntp-stratum) -lt 16 ]; then
echo -n "ntp" > /tmp/timesync
exit 0
fi
fi
for candidate in $(uci -q get system.ntp.server)

View File

@ -0,0 +1,5 @@
STATEFILE="/var/state/ntp-stratum"
if [[ "${stratum}" != "" ]]; then
echo "${stratum}" > "${STATEFILE}"
fi