Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): Add time synchronization check to setupOS #3433

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 set_hwclock_utc() {
echo "* Setting hardware clock to UTC..."
timedatectl set-local-rtc 0
}

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."
}
Comment on lines +16 to +37
Copy link
Member Author

@andrewbattat andrewbattat Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reran installation a number of times on bare metal, and here are the number of chrony retries each installation took:

  • 0
  • 12 (24 seconds)
  • 12 (24 seconds)
  • 12 (24 seconds)
  • 0
  • 12 (24 seconds)
  • 12 (24 seconds)
  • 11 (22 seconds)

Is this acceptable to us? We could just roll this out and if it ever causes a false negative, roll it back. I'm not sure this is worth more of a time investment.


main() {
log_start "$(basename $0)"
set_hwclock_utc
check_ntp
Comment on lines +41 to +42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to sync ntp first, then update the hardware clock.

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
Loading