[systemd-devel] How to ensure a systemd unit waits for ntpd to sync before starting?

Lennart Poettering lennart at poettering.net
Tue Apr 2 08:17:26 UTC 2019

On Di, 02.04.19 13:14, Debraj Manna (subharaj.manna at gmail.com) wrote:

> We have a service that starts at boot. We need to ensure it doesn't start
> until the system clock has been synchronized via ntp. The machines are
> using ntpd.

Well packaged NTP servers should have a separate .service unit that
waits until an NTP sync is reached. For example, systemd's own
systemd-timesyncd.service comes with a companion
systemd-time-wait-sync.service that does this. These units aren't
supposed to be enabled by default (since making boot-up success and
speed dependent on external networking servers is only OK in very
specific setups). If you enable this wait service matching your NTP
implementation then it will order itself before the generic
time-sync.target unit. This target unit is supposed to be a generic
barrier: all NTP implementations that have such a wait service should
order it before that, and all services that are best run after an NTP
sync was reached should be ordered after that.

Now, whether a service like that exists for your NTP server choice I
don't know, it depends on your distro and you upstream of course. If
you have one, then it should be sufficient to "systemctl enable" it,
and then order your unit you want to run after the sync is reached


Lennart Poettering, Berlin

More information about the systemd-devel mailing list