7

How can I recognize which service provides time-sync.target in systemd? Is it configurable or is it hardcoded in systemd? How can I configure my custom time-sync daemon/service to provide this target?

8

Run

systemctl show time-sync.target

to see the information and configuration maintained by systemd for this target. In particular, this will tell you that it is part of the special systemd units and documented there:

Services responsible for synchronizing the system clock from a remote source (such as NTP client implementations) should pull in this target and order themselves before it. All services where correct time is essential should be ordered after this unit, but not pull it in. systemd automatically adds dependencies of type After= for this target unit to all SysV init script service units with an LSB header referring to the "$time" facility.

It is fully configurable (use systemctl edit to override any aspect you want to). As mentioned above, services which provide time synchronisation (e.g. systemd-timesyncd.service) declare that they want this target, and order themselves before it; services which need time synchronisation order themselves after it.

To configure a time synchronisation service, copy the relevant parts of systemd-timesync’s configuration:

[Unit]
Before=time-sync.target
Wants=time-sync.target
  • Services... should pull in this target means Starting the services... should trigger the starting of this target? – TheMeaningfulEngineer Mar 21 at 13:14
  • Pretty much, yes; it means that services ... should declare Wants=time-sync.target, which has the effect of starting time-sync.target when the configuring services are started (but not requiring the target, i.e. the transaction won’t fail if time-sync.target fails). – Stephen Kitt Mar 21 at 13:16
  • And time-sync.target only has a ordering dependency on systemd-timesyncd.service (systemd-timesyncd.service starts before time-sync.target). If systemd-timesyncd.service fails soon after it started, time-sync.target is still reached? – TheMeaningfulEngineer Mar 21 at 13:19
  • That depends on exactly when it fails. If it fails during startup, time-sync.target will not be started; if it fails after startup, time-sync.target will have started too. systemd-timesyncd.service is configured to restart on failure, with no delay, so if it fails, systemd will restart it immediately. – Stephen Kitt Mar 21 at 13:32
  • If it fails during startup - what do you mean with startup here? Would a segfault in systemd-timesyncd.service be a failed startup? (trying to understand what would be considered the threshold from "starting up" to "started") – TheMeaningfulEngineer Mar 21 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.