I need to start a certain service after system clock was correctly stepped by crony.
System time is maintained by chrony (chronyd (chrony) version 3.5 (+CMDMON +NTP +REFCLOCK +RTC -PRIVDROP -SCFILTER -SIGND +ASYNCDNS -SECHASH +IPV6 -DEBUG)
).
Chrony setup, if relevant, is:
server 192.168.100.1 trust minpoll 2 maxpoll 4 polltarget 30 refclock PPS /dev/pps0 refid KPPS trust lock GNSS maxdispersion 3 poll 2 refclock SOCK /var/run/chrony.sock refid GNSS maxdispersion 0.2 noselect makestep 0.1 -1 driftfile /var/lib/chrony/drift rtcsync
example of a “normal, tracking status” is:
/ # chronyc tracking Reference ID : C0A86401 (192.168.100.1) Stratum : 2 Ref time (UTC) : Wed Dec 01 11:52:08 2021 System time : 0.000004254 seconds fast of NTP time Last offset : +0.000000371 seconds RMS offset : 0.000011254 seconds Frequency : 17.761 ppm fast Residual freq : +0.001 ppm Skew : 0.185 ppm Root delay : 0.000536977 seconds Root dispersion : 0.000051758 seconds Update interval : 16.2 seconds Leap status : Normal
while “unsynchronized” (initial) status is:
/ # chronyc tracking Reference ID : 00000000 () Stratum : 0 Ref time (UTC) : Thu Jan 01 00:00:00 1970 System time : 0.000000000 seconds fast of NTP time Last offset : +0.000000000 seconds RMS offset : 0.000000000 seconds Frequency : 0.000 ppm slow Residual freq : +0.000 ppm Skew : 0.000 ppm Root delay : 1.000000000 seconds Root dispersion : 1.000000000 seconds Update interval : 0.0 seconds Leap status : Not synchronised
I seem to remember crony can call a script whenever stratus level changes, but I was unable to find references.
In any case: Is there any way to instruct crony to run a script/program or otherwise send some signal whenever acquires/loses tracking with a valid server?
I am currently relying on a rather ugly: while chronyc tracking | grep -q "Not synchronised"; do sleep 1; done
but a proactive signalling by chronyd
would be preferred.
Details:
- System is a (relatively) small IoT device running Linux (Yocto)
- It has no RTC (it always starts with clock set to Epoch).
- System has no connection to the Internet (initially).
- System has connection to a device having a GNSS receiver and correct time is derived from there.
- There may be a (sometimes ‘very’) long time before GNSS acquires a fix and thus can propagate time.
- At a certain point chrony finally gets the right time and steps system clock. After this is done I need to start a service (or run a script or whatever).
- I am currently polling
chronyc tracking
and parsing status, but that is not really nice.
Advertisement
Answer
I was looking to do the same and came up empty-handed.
I did, however, find chronyc waitsync
, which appears to be a built-in way to do the polling, without the need to parse and sleep explicitly. This works well enough for my case, since I only need to delay a single start-up action.
The existence of this command also hints (albeit by no means proves) that direct triggering may not be supported. If triggering is a hard requirement, rsyslogd
can help.
BTW, one can only admire the enthusiasm of systemd fans, spreading the love even when their purported answer is obviously and completely irrelevant.
Clearly, the target system does NOT use systemd
. The question is about chronyd
, not about systemd-timesyncd
, while systemd-time-wait-sync.service
applies only to the latter.