Skip to content
Advertisement

run script when chrony steps clock

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:

JavaScript

example of a “normal, tracking status” is:

JavaScript

while “unsynchronized” (initial) status is:

JavaScript

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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement