Skip to content

Delay Supervisor start until time has been sychronized#1360

Merged
agners merged 3 commits intohome-assistant:devfrom
agners:enable-time-wait-sync-service
May 12, 2021
Merged

Delay Supervisor start until time has been sychronized#1360
agners merged 3 commits intohome-assistant:devfrom
agners:enable-time-wait-sync-service

Conversation

@agners
Copy link
Member

@agners agners commented May 12, 2021

On first boot, the RTC of many embedded boards can be off. Currently the Supervisor gets started immediately, which then leads to conection failures when trying to connect to https targets since the certificate appears to be invalid (typically the validity is in the future from the boards perspective).

Make sure to delay Supervisor start until time has been synchronized. Wait a maximum of 90s, and continue boot in case synchronization isn't possible (no Internet connectivity).

agners added 3 commits May 12, 2021 16:37
Enable the systemd-time-wait-sync.service by default. This allows to use
the time-sync.target which allows to make sure services only get started
once the time is synchronized.
Use the time-sync.target to make sure that the Supervisor gets stsarted
after the time has been synchronized.
Don't delay startup forever in case time synchronization doesn't work.
This allows to boot the system even without Internet connection.
@agners agners added the os label May 12, 2021
@agners agners marked this pull request as ready for review May 12, 2021 15:08
@agners agners merged commit 2d3119e into home-assistant:dev May 12, 2021
agners added a commit to agners/operating-system that referenced this pull request Aug 17, 2022
With commit 2d3119e ("Delay Supervisor start until time has been
sychronized (home-assistant#1360)") systemd-time-wait-sync.service got enabled, which
waits until systemd-timesyncd synchronizes time with a NTP server.

By default systemd-timesyncd.service and systemd-time-wait-sync.service
are pulled in by sysinit.target. This starts the services before full
network connectivity is established. The first sychronization fails and
systemd-timesyncd only retries after a ratelimit mechanism times out.
This causes a dealy of 30s during startup. While systemd-timesyncd has
a mechanism to (re)try time synchronization when network becomes
online, it seems that those only work properly when systemd-networkd
is used, see also systemd/systemd#24298.

Simply reordering systemd-timesyncd.service after network-online.target
does not work as it causes circular dependencies (NetworkManager itself
depends ultimately on the sysinit.target).

With this change, the services are only pulled in by time-sync.target.
That allows to order the service after network-online.target. With that
the first synchronization succeeds.

This mechanism also works when a NTP server is provided through DHCP.
In that case, a the systemd-timesyncd service is started by the dispatch
script /usr/lib/NetworkManager/dispatcher.d/10-ntp before the systemd
even considers starting the service. Tests show that the default
fallback NTP is not contacted, only the DHCP provided service.
agners added a commit that referenced this pull request Aug 17, 2022
With commit 2d3119e ("Delay Supervisor start until time has been
sychronized (#1360)") systemd-time-wait-sync.service got enabled, which
waits until systemd-timesyncd synchronizes time with a NTP server.

By default systemd-timesyncd.service and systemd-time-wait-sync.service
are pulled in by sysinit.target. This starts the services before full
network connectivity is established. The first sychronization fails and
systemd-timesyncd only retries after a ratelimit mechanism times out.
This causes a dealy of 30s during startup. While systemd-timesyncd has
a mechanism to (re)try time synchronization when network becomes
online, it seems that those only work properly when systemd-networkd
is used, see also systemd/systemd#24298.

Simply reordering systemd-timesyncd.service after network-online.target
does not work as it causes circular dependencies (NetworkManager itself
depends ultimately on the sysinit.target).

With this change, the services are only pulled in by time-sync.target.
That allows to order the service after network-online.target. With that
the first synchronization succeeds.

This mechanism also works when a NTP server is provided through DHCP.
In that case, a the systemd-timesyncd service is started by the dispatch
script /usr/lib/NetworkManager/dispatcher.d/10-ntp before the systemd
even considers starting the service. Tests show that the default
fallback NTP is not contacted, only the DHCP provided service.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants