Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4610

Advanced users • Replace the watchdog.service and wd_keepalive.service with custom ping of the hardware watchdog timer

$
0
0
If my application stops, the Raspberry pi4,5 should reboot so I want to have my application to ping/poke the built-in hardware watchdog timer (BCM2835-wdt).

Because I want my program to be responsible for pinging/poking the watchdog by writing to /dev/watchdog, I have disabled both the watchdog.service and wd_keepalive.service like this:

Code:

sudo systemctl disable watchdog.servicesudo systemctl disable wd_keepalive.service
Pinging the watchdog could the be a command similar to this:

Code:

sudo sh -c "echo 'V' > /dev/watchdog"
But the system does not reboot when this pinging stops.
The command wdctl gives:

Code:

pi@pi119:~ $ sudo wdctlDevice:        /dev/watchdog0Identity:      Broadcom BCM2835 Watchdog timer [version 0]Timeout:       15 secondsTimeleft:      14 secondsPre-timeout:    0 secondsFLAG           DESCRIPTION               STATUS BOOT-STATUSKEEPALIVEPING  Keep alive ping reply          1           0MAGICCLOSE     Supports magic close char      0           0SETTIMEOUT     Set timeout (in seconds)       0           0
This shows always timeleft: 15 or 14 seconds indicating that some process is pinging the /dev/watchdog0 every 1 second. Confirmed by the line: "KEEPALIVEPING Keep alive ping reply 1 0"

This explains why ceasing to

Code:

sudo sh -c "echo 'V' > /dev/watchdog" 
does not trigger a reboot.

But the question is which (zombie) process is triggering the watchdog then if it is not watchdog.service or wd_keepalive.service ? It is not my program. There are no services which are obvious candidates.

As a final verification - this python code will trigger a reboot after 15 second:

Code:

import time# Open the watchdog devicewith open("/dev/watchdog", 'w') as watchdog:    print("Watchdog activated. The system will reboot in 15 seconds if no ping is sent.")    time.sleep(30)  # Wait for 30 seconds, longer than the timeout of 15 seconds
The difference to the sudo sh -c "echo 'V' > /dev/watchdog" is that the python code locks the file /dev/watchdog preventing the zombie from pinging the watchdog.
So it all adds up except - which process is running in the background pinging the watchdog?

I am unsure of the difference between /dev/watchdog and /dev/watchdog0 - so far I have not seen any difference.
Comments are welcomed.

Code:

pi@pi119:~ $ uname -aLinux pi119 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux

Statistics: Posted by h.larsen — Sat Oct 12, 2024 8:37 pm — Replies 5 — Views 79



Viewing all articles
Browse latest Browse all 4610

Trending Articles