Manually use the `timesync-https` service?

Hello,
I saw that recently a new timesync-https service was added to handle updating the system time from an HTTPS service (e.g. in case NTP isn’t working). Here’s the pull request that added it: systemd/timeinit: add HTTPS time synchronisation service by markcorbinuk · Pull Request #2360 · balena-os/meta-balena · GitHub, and it appears that it landed in v2.88.0.

I was wondering if there was a way to trigger this service from my app code (e.g. by executing a bash script)? It would be great to be able to interact with this service on demand, and to check and see if it completed successfully.

The specific scenario I am trying to deal with is making sure that time has been synced before my app starts performing certain actions. Some of my fleet devices are on networks that block NTP, so I have written code to fall back to a manual time update in case NTP doesn’t work. I’d love to be able to check in with the timesync-https service instead of doing my own work to update the system clock when NTP isn’t an option.

Thanks!

Hi, the idea behind the timesync-https service is that it will provide initial time synchronization at boot before starting other services that require a decent time synchronization. It should provide a good-enough system time, that will then be kept across reboots and updated with accuracy via NTP.

If you want to manually run the service from a container, you can follow the instructions in BalenaOS Masterclass - Balena Documentation

and do:

DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket dbus-send --system --dest=org.freedesktop.systemd1 --type=method_call --print-reply /org/freedesktop/systemd1   org.freedesktop.systemd1.Manager.RestartUnit string:"timesync-https.service" string:"replace"
1 Like