Era*_*ore 3 clock ntp embedded-linux beagleboard
我正在使用BeagleBone,因为它没有内置的RTC和备用电池,所以每次重启都会丢失日期.我可以使用命令轻松设置日期:
/ usr/bin/ntpdate -b -s -u pool.ntp.org
但是,如果电源熄灭并重新开始,那么时间就会消失.最新的beaglebone Angstrom linux发行版附带的解决方案是在每半小时更新一次crontab行.但我更愿意在通电时运行一次命令.
我尝试将上面列出的这个命令放在带有@reboot行的crontab中,但是我相信在配置网络之前就已经运行了,或者其他什么都失败了,因为它没有让我在正确的时间拉动电源5分钟然后放入它回到beaglebone.
有没有办法使用ifconfig或类似的东西,只有在网络可用后才能从init.d运行脚本?
opkg install ntp-systemd
systemctl enable ntpdate.service
systemctl enable ntpd.service
Run Code Online (Sandbox Code Playgroud)
编辑/etc/ntp.conf并注释以下行(不存在不存在的硬件时钟的后备,因为ntpdate服务使用"ntpd -q"命令)
#server 127.127.1.0
#fudge 127.127.1.0 stratum 14
Run Code Online (Sandbox Code Playgroud)
安装了两个服务:
/lib/systemd/system/ntpd.service:
[Unit]
Description=Network Time Service
After=network.target
[Service]
Type=forking
PIDFile=/run/ntpd.pid
ExecStart=/usr/bin/ntpd -p /run/ntpd.pid
Run Code Online (Sandbox Code Playgroud)
/lib/systemd/system/ntpdate.service:
[Unit]
Description=Network Time Service (one-shot ntpdate mode)
Before=ntpd.service
[Service]
Type=oneshot
ExecStart=/usr/bin/ntpd -q -g -x
RemainAfterExit=yes
Run Code Online (Sandbox Code Playgroud)
网络启动后启动ntpd(After = network.target),因此日期应该不断同步.但是在ntpd手册页中已经解释过:
当今的大多数操作系统和硬件都包含一个时间(TOY)芯片,以在电源关闭期间保持时间.引导机器时,芯片用于初始化操作系统时间.机器已同步到NTP服务器后,操作系统会不时更正芯片.如果没有TOY芯片或由于某种原因,它的时间超过服务器时间的1000秒,ntpd假定某些事情必定是非常错误的,唯一可靠的操作是操作员干预并手动设置时钟.这会导致ntpd以恐慌消息退出到系统日志.-g选项会覆盖此检查,无论芯片时间如何,时钟都将设置为服务器时间.但是,为了防止损坏的硬件,例如当CMOS电池发生故障或时钟计数器出现故障时,一旦设置了时钟,大于1000s的错误将导致ntpd无论如何都会退出.
所以我们需要在启动ntpd之前设置日期,这是由ntpdate服务通过在启动ntpd.service之前执行"ntpd -q -g -x"来完成的.
从ntpd手册页:
-q在第一次设置时钟后立即退出ntpd.此行为模仿ntpdate程序的行为,该程序将被淘汰.-g和-x选项可与此选项一起使用.注意:使用此选项禁用内核时间规则.
Beaglebone上安装的另一项服务与日期/时间相互作用
timestamp.service
[Unit]
Description=Timestamping service
ConditionPathExists=/etc/timestamp
After=remount-rootfs.service
[Service]
RemainAfterExit=yes
ExecStart=/usr/bin/load-timestamp.sh
ExecStop=/usr/bin/load-timestamp.sh --save
Run Code Online (Sandbox Code Playgroud)
此服务在停止时将当前时间戳存储在/ etc/timestamp中,并从该时间戳开始时设置日期.因此,如果未安装ntpd,手动设置日期并重新启动beaglebone,则日期仅在启动持续时间之后.
| 归档时间: |
|
| 查看次数: |
12457 次 |
| 最近记录: |