Skip to content

Commit 804ebf3

Browse files
committed
00-check-rtc-and-wait-ntp.sh: Add max_retry for the maximum number of sync attempts.
Signed-off-by: Norio Nomura <[email protected]>
1 parent 1aa54e3 commit 804ebf3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pkg/cidata/cidata.TEMPLATE.d/boot/00-check-rtc-and-wait-ntp.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ command -v systemctl >/dev/null 2>&1 || exit 0
1313
systemctl enable systemd-time-wait-sync.service
1414

1515
# For the first boot, where the above setting is not yet active, wait for NTP synchronization here.
16-
until ntp_synchronized=$(timedatectl show --property=NTPSynchronized --value) && [ "${ntp_synchronized}" = "yes" ]; do
16+
max_retry=60 retry=0
17+
until ntp_synchronized=$(timedatectl show --property=NTPSynchronized --value) && [ "${ntp_synchronized}" = "yes" ] ||
18+
[ "${retry}" -gt "${max_retry}" ]; do
1719
time_usec=$(timedatectl show --property=TimeUSec)
1820
echo "${time_usec}, Waiting for NTP synchronization..."
21+
retry=$((retry + 1))
1922
sleep 1
2023
done
2124
# Print the result of NTP synchronization
2225
ntp_message=$(timedatectl show-timesync --property=NTPMessage)
2326
time_usec=$(timedatectl show --property=TimeUSec)
24-
echo "${time_usec}, NTP synchronization complete."
25-
echo "${ntp_message}"
27+
if [ "${ntp_synchronized}" = "yes" ]; then
28+
echo "${time_usec}, NTP synchronization complete."
29+
echo "${ntp_message}"
30+
else
31+
echo "${time_usec}, NTP synchronization timed out."
32+
echo "${ntp_message}"
33+
exit 1
34+
fi

0 commit comments

Comments
 (0)