To my knowledge the busybox ntpd (that we use) does not offer any query interface.
You might need to create that query interface with C for busybox, author the patch for OpenWrt, and hopefully also upstream the patch to busybox...
Alternatively, use chrony ntpd, which offers a query interface if I remember right.
This alternative might be some crude "fetch time with NTP or http protocol from network and compare that to local time" type of crude check, if your need is merely to find out if the time is roughly ok. Use a C NTP library for that?
Really like this! Exactly what I'm after, as I need to delay WireGuard (uplink) until time sync is done (or the WireGuard handshake fails).
So I created /etc/hotplug.d/ntp/20-ntpd-logger like you note, but not seeing anything in the log. Anything "special" that needs to be done ... file permissions, or registering the file somehow? I do know that time sync has been achieved (based on the date / time ).
This has bothered me for some time. Where the heck are the $ stratum, $poll_interval, and $offset variables defined?
I used the default busybox ntpd when I first came here, and never could get this hotplug to spit out the supposed values.
Having a local TS, I just set up a cron using
ntpdate -q 10.10.1.100
server 10.10.1.100, stratum 2, offset -0.013229, delay 0.02811
2 Aug 23:21:46 ntpdate: adjust time server 10.10.1.100 offset -0.013229 sec
As a result of a recent thread, I revisited the NTP wiki series and along with that I reviewed the relevant source openwrt/packages. I cannot find where these variables are either referenced or populated.
I can modify the script to populate values of my choice using
Note that quite much of the documentation is targeted for "OpenWrt with the default daemon packages" users. Chrony, ICS ntp etc. extra packages users will hopefully get documentation from the package upstream.
In my experience, that script does not actually work, and I never figured out why. Rather than debug it, I reimplemented similar functionality for chrony by periodically polling chrony status using chronyc - I'm seeking formal approval from my employer to upstream stuff I've developed "on the clock", but that's taking a lot longer than expected because there are much higher priority things going on.
Some things don't really map well, since it seems like busybox ntpd emits an "offset" event when it changes time by an offset without a stratum change (I'm guessing, I've never actually seen it), while chronyc can't emit events and just provides a "current offset" whenever polled. I was able to implement stratum change by only triggering a stratum hotplug when the stratum was not equal to a previously saved value.
This is a hotplug helper script. It gets called in the /etc/init.d/ntpd and doesn't reside in /etc/hotplug.d/ntp
It sure does! Exactly. In fact here is a snippet from my syslog:
Thu Aug 4 15:48:53 2022 user.notice ntpd: stratum=2 frequency=+18.496 refid=10.10.1.100 poll=11m clock=e696a125.b97903e7 Thu, Aug 4 2022 15:48:53.724
Thu Aug 4 15:59:53 2022 user.notice ntpd: stratum=2 frequency=+18.496 refid=10.10.1.100 poll=11m clock=e696a3b9.c5752ab2 Thu, Aug 4 2022 15:59:53.771
Thu Aug 4 16:10:53 2022 user.notice ntpd: stratum=2 frequency=+18.496 refid=10.10.1.100 poll=11m clock=e696a64d.cdf92dee Thu, Aug 4 2022 16:10:53.804
Thu Aug 4 16:21:53 2022 user.notice ntpd: stratum=3 frequency=+18.435 refid=10.10.1.100 poll=11m clock=e696a8e1.d6c47445 Thu, Aug 4 2022 16:21:53.838
Thu Aug 4 16:32:53 2022 user.notice ntpd: stratum=3 frequency=+18.424 refid=10.10.1.100 poll=11m clock=e696ab75.df711467 Thu, Aug 4 2022 16:32:53.872
Thu Aug 4 16:43:53 2022 user.notice ntpd: stratum=3 frequency=+18.424 refid=10.10.1.100 poll=11m clock=e696ae09.e8465d26 Thu, Aug 4 2022 16:43:53.907
Thu Aug 4 16:54:53 2022 user.notice ntpd: stratum=3 frequency=+18.400 refid=10.10.1.100 poll=11m clock=e696b09d.f0ee152a Thu, Aug 4 2022 16:54:53.941
Notice the time stamp progression - every 11 minutes or 660 seconds a poll runs. On a side note, you will find your drift file will update every hour.
This is my hack on the busybox ntpd hotplug script 20-ntpd-logger from the wiki to produce the above if you are running real ICSntpd. This uses the ntpq runtime to query and populate the current variables.
Yes, I know that. Its role is to trigger scripts that reside in /etc/hotplug/ntp - I have been using such a script to restart OpenVPN on stratum change since OpenVPN goes out to lunch if time jumps while it's running.
The problem is - it doesn't do its job. Anything in /etc/hotplug/ntp NEVER runs when using that hotplug helper. As a result, when I tried switching from busybox ntpd to ISC ntpd, the OpenVPN restart script stopped running, leading to OpenVPN going out to lunch on time sync and staying out to lunch. I tried adding the "logger" example to determine why OpenVPN wasn't restarting - and the initial blip on stratum change and subsequent 11 minute polls never run with the included hotplug helper script. The scripts in /etc/hotplug/ntp were not the problem, since they worked with busybox ntpd and also with the hotplug helper I wrote for chrony
I found that chrony performed better in my use case anyway, so wrote a similar hotplug helper for chrony that parses the output of chronyc to set most of the variables. There's no way I can see to trigger ACTION="step", but so far, ACTION="stratum" does OK, even though in theory, OpenVPN should only need a restart on departure from stratum=16 and not any other stratum change - but in most use cases, the only stratum change is going to be 16->somethingelse and then that stratum will be held