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

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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."
}
andrewbattat marked this conversation as resolved.
Show resolved Hide resolved

main() {
log_start "$(basename $0)"
set_hwclock_utc
check_ntp
andrewbattat marked this conversation as resolved.
Show resolved Hide resolved
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