-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): Add time synchronization check to setupOS (#3433)
NODE-1504 - Force the RTC to keep time in UTC - Add a check for if system clock is synchronized
- Loading branch information
1 parent
2c79ddc
commit 51f818e
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
set -o pipefail | ||
|
||
SHELL="/bin/bash" | ||
PATH="/sbin:/bin:/usr/sbin:/usr/bin" | ||
|
||
source /opt/ic/bin/functions.sh | ||
|
||
function check_ntp() { | ||
echo "* Checking Chrony status..." | ||
|
||
systemctl is-active --quiet chrony | ||
log_and_halt_installation_on_error "$?" "Chrony service not running or not active." | ||
|
||
retries=0 | ||
max_retries=30 | ||
while [ "$(timedatectl show -p NTPSynchronized --value)" != "yes" ]; do | ||
if [ $retries -ge $max_retries ]; then | ||
local service_logs=$(journalctl -u chrony.service --no-pager) | ||
local log_message="System clock is not synchronized.\n\nChrony service logs:\n${service_logs}" | ||
log_and_halt_installation_on_error 1 "${log_message}" | ||
fi | ||
|
||
echo "* Chrony not yet synchronized. Waiting 2 seconds before retry..." | ||
sleep 2 | ||
((retries++)) | ||
done | ||
|
||
echo "* Chrony is running and time is in sync." | ||
} | ||
|
||
function set_hwclock_utc() { | ||
echo "* Setting hardware clock to UTC..." | ||
timedatectl set-local-rtc 0 | ||
} | ||
|
||
main() { | ||
log_start "$(basename $0)" | ||
check_ntp | ||
set_hwclock_utc | ||
log_end "$(basename $0)" | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters