Jan Hugo Prins wrote on 25/03/2021 14:11:
Hi,
> Does systemd give me a different way to check if the time is in sync?
> Is there a way to create this dependency without implying a restart when
> ntpd restarts?
https://unix.stackexchange.com/questions/388586/systemd-requires-vs-wants
<https://unix.stackexchange.com/questions/388586/systemd-requires-vs-wants>
just replace "Requires" with "Wants", it does exactly the same but your
Tomcat would also get started if "time-sync.target" is missing *but* it
would not be stopped just because ntpd is stopped
there are really very few cases when Requires is really what someone wants
We first tried it with wants, but wants does start the application
server even if the time-sync.target does not work.
From the man page:
Units listed in this option will be started if the
configuring unit is. *However, if the listed units fail to start or
cannot be added to the**
** transaction, this has no impact on the validity of the
transaction as a whole*, and this unit will still be started. This is
the recommended
way to hook the start-up of one unit to the start-up of
another unit.
We don't want tomcat to start when time-sync doesn't succeed, but when
ntpd restarts it should not influence tomcat.
How about using Wants as Reindl suggests, but also adding an:
ExecStartPre=systemctl is-active -q time-sync.target
Or something similar which ensures that ntp has run and is working. e.g.
you may want to ensure that whatever you run here waits a bit after NTP
started to ensure stabilisation of the time if drift compensation takes
a little time to sync up )or however that works). Essentially a bit like
networkd-wait-online where the network can be physically connected (cf.
ntp started) but nothing is routable yet (cf. clock not yet actually
sync'ed)
This approach is such that way you get the failure when starting the
service, but it won't affect runtime ongoing.
Just a thought.
Col
_______________________________________________
systemd-devel mailing list
systemd-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel