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

[Snap] Implement NTP API #3161

Open
benfrancis opened this issue Aug 22, 2024 · 4 comments
Open

[Snap] Implement NTP API #3161

benfrancis opened this issue Aug 22, 2024 · 4 comments
Labels
snap Issues relating to the snap package task
Milestone

Comments

@benfrancis
Copy link
Member

Implement a mechanism by which the gateway can check the status of an NTP server and restart it.

This is used by the gateway to check whether the clock has been set from the internet, in order to warn the user about potential certificate validation problems if the system clock is wrong.

E.g. https://github.com/WebThingsIO/gateway/blob/master/src/platforms/linux-raspbian.ts#L976

@benfrancis benfrancis converted this from a draft issue Aug 22, 2024
@benfrancis benfrancis added this to the 2.0 milestone Aug 22, 2024
@benfrancis benfrancis added snap Issues relating to the snap package task labels Aug 22, 2024
@benfrancis benfrancis moved this from Product Backlog to Sprint Backlog in WebThings Gateway Oct 17, 2024
@benfrancis
Copy link
Member Author

@dilyn-corner
Copy link
Contributor

timeserver-control probably covers precisely what you need; it may be worth investigating if time-control and timezone-control may also be relevant.

There's also the ptp interface, with an example implementation.

If timeserver-control suffices, Ogra actually has a simple implementation example here which should still hold just fine.

@benfrancis
Copy link
Member Author

@dilyn-corner As I understand it, what @ogra1's tool does is allow the user to set and unset an NTP server endpoint.

Looking more closely at the Raspbian back end for WebThings Gateway I see that it does two things:

  • getNtpStatus() - Calls timedatectl status to determine whether or not the system time is currently synchronised with an NTP server
  • restartNtpSync() Calls systemctl restart systemd-tumesyncd.service to restart the NTP service with intention of synchronising the clock, and reports on success or failure

I believe the reason these two functions exist are that during first time setup it's important the system clock is set correctly in order to avoid errors during the process of issuing a TLS certificate from LetsEncrypt for a new unique subdomain and then redirecting to that subdomain. This is particularly important on a Raspberry Pi which lacks a real-time clock.

During first time setup the gateway will display a warning to the user if it detects that the system clock is not synchronised. It will then attempt to restart the NTP service and poll the gateway for a synchronised status before removing the warning.

Am I right to assume that an NTP server is set on Ubuntu Core by default?

If so then what we need is a bit different to what @ogra1's tool provides. Rather than set an NTP service endpoint, we need to be able to query the synchronisation status of the NTP service, and potentially restart the NTP service if necessary.

@dilyn-corner / @ogra1 Is this possible to do by connecting the timeserver-control interface and using systemd-timedated, and if so how? Via a DBus API? Or would I need to compile and bundle timedatectl?

@ogra1
Copy link
Contributor

ogra1 commented Oct 23, 2024

The timeserver-control interface gives you full access to the timedatectl command but it does indeed not open a path to call systemctl restart systemd-timesyncd.service ... however, timedatectl offers a set-ntp command, if you toggle it off and on again this will trigger a forced re-sync so I guess you could patch the restartNtpSync() function to use this instead of systemctl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
snap Issues relating to the snap package task
Projects
Status: Sprint Backlog
Development

No branches or pull requests

3 participants