[Raspberry Pi]如何將看門狗(WatchDog)服務建置在樹莓派的Ubuntu作業系統中?

看門狗(WatchDog)服務常應用於連網的嵌入式邊緣設備等IOT裝置和實體伺服器,主要是若這些連網裝置分散在各個應用環境中執行對應任務,例如感測物理數據,監控影像數據或執行各式Docker服務,當連網裝置因故異常,同時又處於無人值守而無法手動重啟的狀態下,此時看門狗(WatchDog)服務可根據設定條件,協助連網裝置自動重啟並恢復到執行對應任務的狀態。

看門狗(WatchDog)的運作原理是一個計時器(timer),若連網裝置的系統運行符合設定條件,即表示系統運行正常,守護程序則定期復位該計時器,使系統持續運作不重啟,俗稱"餵狗";反之,若系統運作不正常而超時,則系統重啟。另外,看門狗服務分為軟體式和硬體式,相較於軟體式看門狗,硬體式看門狗指的是有一個獨立硬體模組嵌入在裝置的晶片中,實現當系統完全死當時,也可自動重啟的功能。本文將利用樹莓派已具備看門狗硬體模組,在Ubuntu作業系統中設定和運行看門狗(WatchDog)服務。

a.查詢該樹莓派搭載的watchdog timer模組規格

由下列指令取得樹莓派5配備Broadcom BCM2835 watchdog timer

raspberry@rpi5-01:~ $ sudo dmesg | grep wdt
[    0.475696] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer

b.安裝watchdog並加載bcm2835_wdt模組 

經上述查詢,在 Raspberry Pi 5 上,bcm2835-wdt 是用于硬件 Watchdog 的内核模块。並利用modprobe加載該模組,不用重新開機。

sudo apt updatesudo apt install watchdogsudo modprobe bcm2835_wdt

c.配置watchdog 

1.依照下列內容配置/etc/watchdog.conf文件。
sudo nano /etc/watchdog.conf
# ====================================================================# Configuration for the watchdog daemon. For more information on the# parameters in this file use the command 'man watchdog.conf'# ====================================================================# =================== The hardware timer settings ====================## For this daemon to be effective it really needs some hardware timer# to back up any reboot actions. If you have a server then see if it# has IPMI support. Otherwise for Intel-based machines try the iTCO_wdt# module, otherwise (or if that fails) then see if any of the following# module load and work:## it87_wdt it8712f_wdt w83627hf_wdt w83877f_wdt w83977f_wdt## If all else fails then 'softdog' is better than no timer at all!# Or work your way through the modules listed under:## /lib/modules/`uname -r`/kernel/drivers/watchdog/## To see if they load, present /dev/watchdog, and are capable of# resetting the system on time-out.# Uncomment this to use the watchdog device driver access "file".watchdog-device = /dev/watchdog# Uncomment and edit this line for hardware timeout values that differ# from the default of one minute.watchdog-timeout = 60# If your watchdog trips by itself when the first timeout interval# elapses then try uncommenting the line below and changing the# value to 'yes'.#watchdog-refresh-use-settimeout = auto# If you have a buggy watchdog device (e.g. some IPMI implementations)# try uncommenting this line and setting it to 'yes'.#watchdog-refresh-ignore-errors = no# ====================== Other system settings ========================## Interval between tests. Should be a couple of seconds shorter than# the hardware time-out value.interval = 10# The number of intervals skipped before a log message is written (i.e.# a multiplier for 'interval' in terms of syslog messages)#logtick        = 1# Directory for log files (probably best not to change this)#log-dir = /var/log/watchdog# Email address for sending the reboot reason. This needs sendmail to# be installed and properly configured. Maybe you should just enable# syslog forwarding instead?#admin = root# Lock the daemon in to memory as a real-time process. This greatly# decreases the chance that watchdog won't be scheduled before your# machine is really loaded.realtime = yespriority = 1# ====================== How to handle errors  =======================## If you have a custom binary/script to handle errors then uncomment# this line and provide the path. For 'v1' test binary files they also# handle error cases.#repair-binary = /usr/sbin/repair#repair-timeout = 60# The retry-timeout and repair limit are used to handle errors in a# more robust manner. Errors must persist for longer than this to# action a repair or reboot, and if repair-maximum attempts are# made without the test passing a reboot is initiated anyway.#retry-timeout = 60#repair-maximum = 1# Configure the delay on reboot from sending SIGTERM to all processes# and to following up with SIGKILL for any that are ignoring the polite# request to stop.#sigterm-delay = 5# ====================== User-specified tests ========================## Specify the directory for auto-added 'v1' test programs (any executable# found in the 'test-directory should be listed).#test-directory = /etc/watchdog.d# Specify any v0 custom tests here. Multiple lines are permitted, but# having any 'v1' programs/scripts discovered in the 'test-directory' is# the better way.#test-binary =# Specify the time-out value for a test error to be reported.#test-timeout = 60# ====================== Typical tests ===============================## Specify any IPv4 numeric addresses to be probed.# NOTE: You should check you have permission to ping any machine before# using it as a test. Also remember if the target goes down then this# machine will reboot as a result!#ping = 172.21.0.1#ping = 192.168.1.1#使用google的公共DNS IP(8.8.8.8)做ping測試ping                    = 8.8.8.8# Set the number of ping attempts in each 'interval' of time. Default# is 3 and it completes on the first successful ping.# NOTE: Round-trip delay has to be less than 'interval' / 'ping-count'# for test success, but this is unlikely to be exceeded except possibly# on satellite links (very unlikely case!).ping-count = 3# Specify any network interface to be checked for activity.#interface = eth0# Specify any files to be checked for presence, and if desired, checked# that they have been updated more recently than 'change' seconds.#file = /var/log/syslog#change = 1407# Uncomment to enable load average tests for 1, 5 and 15 minute# averages. Setting one of these values to '0' disables it. These# values will hopefully never reboot your machine during normal use# (if your machine is really hung, the loadavg will go much higher# than 25 in most cases).max-load-1 = 24max-load-5 = 18max-load-15 = 12# Check available memory on the machine.## The min-memory check is a passive test from reading the file# /proc/meminfo and computed from MemFree + Buffers + Cached# If this is below a few tens of MB you are likely to have problems.## The allocatable-memory is an active test checking it can be paged# in to use.## Maximum swap should be based on normal use, probably a large part of# available swap but paging 1GB of swap can take tens of seconds.## NOTE: This is the number of pages, to get the real size, check how# large the pagesize is on your machine (typically 4kB for x86 hardware).min-memory = 1#allocatable-memory = 1#max-swap = 0# Check for over-temperature. Typically the temperature-sensor is a# 'virtual file' under /sys and it contains the temperature in# milli-Celsius. Usually these are generated by the 'sensors' package,# but take care as device enumeration may not be fixed.temperature-sensor = /sys/class/thermal/thermal_zone0/tempmax-temperature = 95000# Check for a running process/daemon by its PID file. For example,# check if rsyslogd is still running by enabling the following line:#pidfile = /var/run/rsyslogd.pid
2.內容說明
  • watchdog-device = /dev/watchdog : 指定 Watchdog 設備文件,通常是 /dev/watchdog。這是硬件或軟件計時器的接口,守護進程會定期與該設備通信以防止系統重啟。
  • watchdog-timeout = 60 : 設定硬件計時器的超時值(以秒為單位)。默認為 60 秒,即守護進程需要每分鐘餵狗一次,以防止系統重啟。
  • interval = 10 : 設定兩次檢測間的時間間隔(秒)。應比硬件計時器的超時值稍短,以確保守護進程能在超時前進行檢測。
  • realtime = yes 和 priority = 1 : 使守護進程為實時進程,並設置進程優先級,以確保其即使在高負載下也能被調用。
  • ping = 8.8.8.8 : 使用google公共DNS作為Ping的對象。換言之,若藉由與google的連結失效,表示外網不通,守護進程即會觸發系統重啟。
  • ping-count = 3 : 每次間隔內的 Ping 嘗試次數。默認為 3。
  • max-load-1 = 24, max-load-5 = 18, max-load-15 = 12 : 檢測系統負載(1分鐘、5分鐘和15分鐘平均值)。如果負載超過設定值,系統將被重啟。
  • min-memory = 1 : 檢查系統可用內存是否低於指定值(以頁數為單位)。
  • temperature-sensor = /sys/class/thermal/thermal_zone0/temp 和 max-temperature = 95000 : 檢測系統溫度(以毫攝氏度為單位)。超過設定溫度95℃,將觸發系統重啟。

d.運行watchdog服務 

啟動watchdog,並查看該服務是否呈現active。

sudo systemctl start watchdogsudo systemctl status watchdog

上述配置中,其中有一個部分是藉由偵測外網是否斷線來作為觸發系統重啟的條件,可簡易藉由網路斷開與否來測試看門狗服務是否正常運行。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/43363.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux进程状态补充(10)

文章目录 前言一、阻塞二、挂起三、运行R四、休眠D五、四个重要概念总结 前言 上篇内容大家看的云里雾里,这实在是正常不过,因为例如 写实拷贝 等一些概念的深层原理我还没有讲解,大家不用紧张,我们继续往下学习就行!&…

RPCGC阅读

24年的MM 创新 现有点云压缩工作主要集中在保真度优化上。 而在实际应用中,压缩的目的是促进机器分析。例如,在自动驾驶中,有损压缩会显着丢失户外场景的详细信息。在三维重建中,压缩过程也会导致场景数据中语义信息(Contour)的…

keil中文注释出现乱码怎么解决

keil中文注释出现乱码怎么解决 在keil–edit–configuration中encoding改为chinese-GB2312

Linux的进程优先级调度学习笔记

Linux的进程优先级数值范围 范围 -20 到 19&#xff0c;数值越大优先级越低 示例代码 下面是一个简单的 C 语言示例&#xff0c;它演示了如何在 Linux 下修改进程的优先级并观察调度影响。 #include <stdio.h> #include <stdlib.h> #include <unistd.h> …

YOLOv8+ Deepsort+Pyqt5车速检测系统

该系统通过YOLOv8进行高效的目标检测与分割&#xff0c;结合DeepSORT算法完成目标的实时跟踪&#xff0c;并利用GPU加速技术提升处理速度。系统支持模块化设计&#xff0c;可导入其他权重文件以适应不同场景需求&#xff0c;同时提供自定义配置选项&#xff0c;如显示标签和保存…

权限提升—Windows权限提升进程注入令牌窃取服务启动

前言 依旧是提权的内容啦&#xff0c;上次讲的是利用漏洞来进行提权&#xff0c;今天我们主要讲的是利用Windows中的服务、进程等东西进行权限提升。 服务启动 首先要知道一点&#xff0c;就是windows中服务是以system权限运行的&#xff0c;假如我们创建一个运行后门的服务…

数据结构与算法——顺序表之手撕OJ题

文章目录 一、前言二、拿捏OJ题2.1移除元素2.2删除有序数组中的重复项2.3合并两个有序数组 三、总结 一、前言 Do you study today?up在上一次已经讲解完毕了有关顺序表的所有知识&#xff0c;不知道大家是否已经沉淀完毕了呢&#xff1f;有一句老话说得好啊——光看不练假把…

如何在 AI 搜索引擎(GEO)霸屏曝光,快速提升知名度?

虽然大多数人仍然使用 Google 来寻找答案&#xff0c;但正在发生快速转变。ChatGPT、Copilot、Perplexity 和 DeepSeek 等 LLM 已成为主流。这主要是因为每个都有自己的免费和公共版本&#xff0c;并且总是有重大的质量改进。 许多人每天都使用这些工具来提问和搜索互联网&…

4.训练篇2-毕设篇

resnet # 1. 从 torchvision 中加载预训练的 ResNet18 模型 # pretrainedTrue 表示使用在 ImageNet 上预训练过的参数&#xff0c;学习效果更好 base_model_resnet18 models.resnet18(pretrainedTrue)# 2. 获取 ResNet18 模型中全连接层&#xff08;fc&#xff09;的输入特征…

电磁兼容EMC概述

最近重新学了下电磁兼容&#xff0c;对这个东西更清晰了一些&#xff0c;就重新写了一篇&#xff0c;有不足的地方欢迎的大家在评论区里和我交流。 电磁兼容 电磁兼容指的是什么呢&#xff1f;指的是设备在其电磁环境中性能不受降级地正常运行并不对其他设备造成无法承受的电…

坚持“大客户战略”,昂瑞微深耕全球射频市场

北京昂瑞微电子技术股份有限公司&#xff08;简称“昂瑞微”&#xff09;是一家聚焦射频与模拟芯片设计的高新技术企业。随着5G时代的全面到来&#xff0c;智能手机、智能汽车等终端设备对射频前端器件在通信频率、多频段支持、信道带宽及载波聚合等方面提出了更高需求&#xf…

AI赋能职教革新:生成式人工智能(GAI)认证重构技能人才培养新范式

在数字化浪潮的推动下&#xff0c;职业教育正经历着前所未有的变革。面对快速变化的市场需求和技术发展&#xff0c;如何培养具备高技能、高素质的人才成为了职业教育的重要课题。而在这个过程中&#xff0c;人工智能&#xff08;AI&#xff09;技术的融入&#xff0c;无疑为职…

Python:日志管理器配置

日志模块组件&#xff1a; 日志器logger&#xff1a;提供应用程序调用的接口 处理器handler&#xff1a;将日志发送到指定的位置 过滤器filter&#xff1a;过滤日志信息 格式器formatter&#xff1a;格式化输出日志 如何配置日志管理器&#xff1a; #导入模块 import log…

城电科技|零碳园区光伏太阳花绽放零碳绿色未来

近日&#xff0c;珠海城电科技自主研发生产的三轴跟踪光伏太阳花在长沙某智慧零碳园区完成安装调试&#xff0c;正式投入运营。作为集“科技能源艺术”于一体的新能源太阳能光伏发电设备&#xff0c;这一创新艺术光伏景观不仅为园区注入绿色动能&#xff0c;更凭借独特的科技美…

c++ - 右击一个cpp文件,但是编译菜单项是灰的

文章目录 c - 右击一个cpp文件&#xff0c;但是编译菜单项是灰的概述END c - 右击一个cpp文件&#xff0c;但是编译菜单项是灰的 概述 VS2019, 整理工程&#xff0c;在编译&#xff0c;工程报错&#xff0c;说有个函数的实现没找到。 有实现part_opt.cpp&#xff0c;头文件也…

29_项目

目录 http.js 1、先注册账号 register.html 2、再登录 login.html 3、首页 index.html 4 详情 details.html cart.html css index.css register.css details.css 演示 进阶 http.js let baseURL "http://localhost:8888"; let resgiterApi baseURL &…

vmware 创建win10 系统,虚拟机NAT网络设置

虚拟机设置&#xff1a; 物理机本机创建桥接&#xff1a; 如何创建桥接&#xff0c;请自行脑补~

API 请求需要证书认证? 如何在 Postman 中正确配置和使用?

本文来介绍 Postman 提供的管理证书功能如何配置&#xff0c;要了解更多相关的知识&#xff0c;可访问 Postman 证书 模块。 管理客户端证书&#xff0c;点击对应的按钮&#xff0c;首先选择 SETTINGS &#xff0c;然后选择 Certificate 选项卡&#xff0c;如图所示&#xff1…

强大的AI网站推荐(第四集)—— Gamma

网站&#xff1a;Gamma 号称&#xff1a;展示创意的新媒介 博主评价&#xff1a;快速展示创意&#xff0c;重点是展示&#xff0c;在几秒钟内快速生成幻灯片、网站、文档等内容 推荐指数&#xff1a;&#x1f31f;&#x1f31f;&#x1f31f;&#x1f31f;&#x1f31f;&#x…

信息学奥赛一本通 1609:【例 4】Cats Transport | 洛谷 CF311B Cats Transport

【题目链接】 ybt 1609&#xff1a;【例 4】Cats Transport 洛谷 CF311B Cats Transport 【题目考点】 1. 动态规划&#xff1a;斜率优化动规 【解题思路】 解法1&#xff1a;设a点的前缀和 输入的 d d d序列是从 d 2 d_2 d2​到 d n d_n dn​&#xff0c;共n-1个数字。人…