大网数据广告活动
服务器运维问答

Is it possible to check NTPd status on a Busybox system?

· 52CE 我爱测

I need to know if current date/time is reliable in a small embedded Linux system Busybox-based. I have Busybox ntpd running, but apparently there is no program to to query status. On a more conventional Linux installation I would…

问题原文

原帖链接 · ZioByte · CC BY-SA 3.0

I need to know if current date/time is reliable in a small embedded Linux system Busybox-based.

I have Busybox ntpd running, but apparently there is no program to to query status.

On a more conventional Linux installation I would use ntpdc, ntpq, ntpstat or even timedatectl, but none of these is available on this Busybox/Buildroot system.

What else can I do?

已采纳解答

原帖链接 · mikewse · CC BY-SA 4.0

BusyBox does not provide the IPC/RPC interfaces that are needed to query the status of a running BusyBox NTP daemon, so even if you install one of the mentioned query utilities they will not be able to talk to BusyBox ntpd.

Running ntpd -w as mentioned in another answer will simply start another BusyBox ntpd instance from scratch and this new one will not talk to an already running ntpd process.

There is however another way to get status information from BusyBox ntpd, by using its program/script interface. See the -S flag:

~# ntpd --help
BusyBox v1.30.1 () multi-call binary.

Usage: ntpd [-dnqNwl] [-I IFACE] [-S PROG] [-p PEER]...

NTP client/server

        -d      Verbose (may be repeated)
        -n      Do not daemonize
        -q      Quit after clock is set
        -N      Run at high priority
        -w      Do not set time (only query peers), implies -n
        -S PROG Run PROG after stepping time, stratum change, and every 11 min
        -p PEER Obtain time from PEER (may be repeated)
        -l      Also run as server on port 123
        -I IFACE Bind server to IFACE, implies -l

The specified program will be executed regularly depending on different time events and NTP information is supplied as args to the program and in its environment. I find no info about this interface so the source code seems to be the docs in this case:

https://git.busybox.net/busybox/tree/networking/ntpd.c

Look up the function run_script() and you can see that it calls the external program with action as argument and stratum, freq_drift_ppm, poll_interval and offset as environment variables.

Chances are that your embedded Linux distro is already hooking into this interface. On my OpenWrt box ntpd is running with this command line:

/usr/sbin/ntpd -n -N -S /usr/sbin/ntpd-hotplug -p 0.openwrt.pool.ntp.org -p 1.openwrt.pool.ntp.org -p 2.openwrt.pool.ntp.org -p 3.openwrt.pool.ntp.org

and as you can see the program interface is hooking into OpenWrt's procd hotplug support. In OpenWrt this means that you instead add your NTP scripts to /etc/hotplug.d/ntp but the information supplied to your script is still the same, see NTP section here:

https://openwrt.org/docs/guide-user/base-system/hotplug

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-04-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。