简体   繁体   English

如何在看门狗执行之前将日志复制到闪存?

[英]How to copy logs to flash before watchdog execution?

How to execute some script (in my case it would script which copies logs to flash or copies logs remotely) before watchdog execution?如何在看门狗执行之前执行一些脚本(在我的情况下,它是将日志复制到闪存或远程复制日志的脚本)?

Should I modify linux kernel watchdog driver?我应该修改linux内核看门狗驱动程序吗? If so in which method?如果是,用哪种方法? Or maybe it is possible somehow to configure this by:或者也许可以通过以下方式配置它:

/etc/default/watchdog
/etc/watchdog.conf

However we have busybox installed where watchdog configuration is limited.但是,我们安装了busybox,但看门狗配置有限。 I cannot find anything on google, what is suprised as this is basic problem which needs to be solved - everybody wants to have logs after watchdog reset in persistent memory, flash what is not /var/log/ path.我在谷歌上找不到任何东西,令人惊讶的是,这是需要解决的基本问题 - 每个人都希望在持久内存中看门狗重置后有日志,闪存不是 /var/log/ 路径。

Of course solution to copy from time to time logs to flash in normal device lifecycle is not good idea as there should be some solution how to do this when watchdog timeout on feeding /dev/watchdog expires.当然,在正常设备生命周期中不时将日志复制到闪存的解决方案不是一个好主意,因为当 /dev/watchdog 上的看门狗超时到期时,应该有一些解决方案如何执行此操作。

On a linux kernel newer than 4.9 you should have the availability of the pretimeout governor framework which would allow you to write a linux kernel driver which would react on the detection of a pre-timeout.在高于 4.9 的 linux 内核上,您应该可以使用 pretimeout 调控器框架,它允许您编写一个 linux 内核驱动程序,该驱动程序将对检测到的 pre-timeout 做出反应。 A solution like this is well beyond the scope of a simple question and answer, so I'm leaving my original answer stand.像这样的解决方案远远超出了简单问答的范围,所以我离开了我原来的答案。

TL;DR:特尔;博士:

If the problem is detectable while the OS is still running you can flush the logs.如果在操作系统仍在运行时可以检测到问题,您可以刷新日志。 If the problem is caused by the OS locking up then you won't have an opportunity to fix the issue as hardware will reset the box.如果问题是由操作系统锁定引起的,那么您将没有机会解决问题,因为硬件会重置盒子。

There are two things here:这里有两件事:

  • Watchdog device看门狗装置
  • Watchdog program看门狗程序

The watchdog device is typically a hardware timer that will do 'something specifically low level' when it's timer expires.看门狗设备通常是一个硬件定时器,当它的定时器到期时,它会做“特别低级的事情”。 The most common low level thing to do is reset the box.最常见的低级操作是重置框。 There is no OS involvement in this if it happens in hardware.如果它发生在硬件中,则没有操作系统参与其中。 You will have no opportunity to do anything high level once that timer runs out - eg writing log files somewhere.一旦计时器用完,您将没有机会做任何高级别的事情 - 例如在某处写入日志文件。

The watchdog program is a tool that reassures the watchdog device periodically as long as it's check conditions are met.看门狗程序是一种工具,只要它的检查条件满足,它就会定期让看门狗设备放心。

The busybox watchdog timer's condition is a simple loop (pseudo code): busybox 看门狗定时器的条件是一个简单的循环(伪代码):

while (1) {
    # reassure watchdog
    # sleep some time
}

so if the program stops running - eg by an OS lockup or termination of the program then the underlying hardware will simply kick the box.所以如果程序停止运行——例如由于操作系统锁定或程序终止,那么底层硬件将简单地启动。

The 'bigger' watchdog binary provides a bunch of checks, and if they fail, then it will trigger the repair-binary option in the /etc/watchdog.conf to try to recover. 'bigger' 看门狗二进制文件提供了一堆检查,如果它们失败,那么它将触发/etc/watchdog.confrepair-binary选项以尝试恢复。 This would be a potential point to flush the logs.这将是刷新日志的潜在点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM