Skip to content

Commit

Permalink
feat(node): Add time synchronization check to setupOS (#3433)
Browse files Browse the repository at this point in the history
NODE-1504

- Force the RTC to keep time in UTC
- Add a check for if system clock is synchronized
  • Loading branch information
andrewbattat authored Jan 16, 2025
1 parent 2c79ddc commit 51f818e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions ic-os/components/setupos-scripts/check-ntp.sh
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
1 change: 1 addition & 0 deletions ic-os/components/setupos-scripts/setupos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ main() {
/opt/ic/bin/check-config.sh
/opt/ic/bin/check-hardware.sh
/opt/ic/bin/check-network.sh
/opt/ic/bin/check-ntp.sh
if kernel_cmdline_bool_default_true ic.setupos.perform_installation; then
true
else
Expand Down
1 change: 1 addition & 0 deletions ic-os/components/setupos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ component_files = {
Label("//ic-os/components/setupos-scripts:check-hardware.sh"): "/opt/ic/bin/check-hardware.sh",
Label("//ic-os/components/setupos-scripts:install-hostos.sh"): "/opt/ic/bin/install-hostos.sh",
Label("//ic-os/components/setupos-scripts:check-network.sh"): "/opt/ic/bin/check-network.sh",
Label("//ic-os/components/setupos-scripts:check-ntp.sh"): "/opt/ic/bin/check-ntp.sh",
Label("//ic-os/components/setupos-scripts:output-wrapper.sh"): "/opt/ic/bin/output-wrapper.sh",
Label("//ic-os/components/setupos-scripts:setupos.sh"): "/opt/ic/bin/setupos.sh",
Label("//ic-os/components/setupos-scripts:config.service"): "/etc/systemd/system/config.service",
Expand Down

0 comments on commit 51f818e

Please sign in to comment.