Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:hardware:watchdog [2020/09/21 07:47] – [USB watchdogs] code unified vgaeteradocs:guide-user:hardware:watchdog [2021/11/01 11:39] – [USB watchdogs] vgaetera
Line 7: Line 7:
  
 For x86 hardware you have some kmods to choose: For x86 hardware you have some kmods to choose:
-  * ''kmod-it87-wdt'' / ''kmod-sp5100_tco'' - AMD hardware +  * AMD: [[packages:pkgdata:kmod-it87-wdt]], [[packages:pkgdata:kmod-sp5100_tco]] 
-  * ''kmod-itco-wdt'' - Intel hardware +  * Intel: [[packages:pkgdata:kmod-itco-wdt]] 
-  * ''kmod-w83627hf-wdt'' - can work for both+  * Generic: [[packages:pkgdata:kmod-w83627hf-wdt]]
  
 There are also USB-based watchdogs, which will be discussed below in their own sub-section because they are not handled by procd in any way. There are also USB-based watchdogs, which will be discussed below in their own sub-section because they are not handled by procd in any way.
  
 The procd watchdog code always uses the primary watchdog device ''/dev/watchdog''. The procd watchdog code always uses the primary watchdog device ''/dev/watchdog''.
-You can configure what watchdog that is (ie GSC Watchdog or SoC watchdog) by disabling all but the desired watchdog in the kernel configuration, or not installing watchdog kmods for x86 architecture.+You can configure what watchdog that is (i.e. GSC Watchdog or SoC watchdog) by disabling all but the desired watchdog in the kernel configuration, or not installing watchdog kmods for x86 architecture.
  
 ===== Controlling the watchdog ===== ===== Controlling the watchdog =====
 You can see the current configuration of the watchdog service via ubus: You can see the current configuration of the watchdog service via ubus:
- 
-If there is a watchdog available: 
  
 <code bash> <code bash>
Line 30: Line 28:
 </code> </code>
  
-If no watchdog is available+If no watchdog is available, the status parameter is ''offline''.
- +
-<code bash> +
-# ubus call system watchdog +
-+
-        "status": "offline", +
-        "timeout": 30, +
-        "frequency":+
-+
-</code>+
  
 While there is no UCI configuration available for these options, you can change them in an rc script such as ''/etc/rc.local''. While there is no UCI configuration available for these options, you can change them in an rc script such as ''/etc/rc.local''.
Line 45: Line 34:
 <code bash> <code bash>
 # Change timeout to 60s # Change timeout to 60s
-ubus call system watchdog '{ "timeout": 60 }'+ubus call system watchdog '{"timeout":60}' 
 # Change frequency to 1s # Change frequency to 1s
-ubus call system watchdog '{ "frequency": 1 }'+ubus call system watchdog '{"frequency":1}'
 </code> </code>
  
-To stop the service:+To bypass procd, enable the magicclose feature, stop the service and control the watchdog manually:
  
 <code bash> <code bash>
-ubus call system watchdog '{ "stop": true }'+ubus call system watchdog '{"magicclose":true}' 
 +ubus call system watchdog '{"stop":true}' 
 +while :; do echo 1 > /dev/watchdog; sleep 5; done
 </code> </code>
  
 Note that watchdog will cause a reset after it expires. Note that watchdog will cause a reset after it expires.
- 
-===== Manually control hardware watchdog ===== 
-If you just stop procd from tickling the hardware watchdog you still can't manually tickle watchdog: 
- 
-<code bash> 
-# ubus call system watchdog '{"stop": true}' 
-{ 
-        "status": "stopped", 
-        "timeout": 30, 
-        "frequency": 5, 
-        "magicclose": false 
-} 
- 
-# echo 1 > /dev/watchdog 
--ash: can't create /dev/watchdog: Resource busy 
-</code> 
- 
-But if you enable magicclose feature then you have control: 
- 
-<code bash> 
-# ubus call system watchdog '{"magicclose": true}' 
-{ 
-        "status": "running", 
-        "timeout": 30, 
-        "frequency": 5, 
-        "magicclose": true 
-} 
- 
-# ubus call system watchdog '{"stop": true}' 
-{ 
-        "status": "offline", 
-        "timeout": 0, 
-        "frequency": 0, 
-        "magicclose": true 
-} 
- 
-# echo 1 > /dev/watchdog 
-# 
-</code>  
  
 ===== USB watchdogs ===== ===== USB watchdogs =====
Line 110: Line 63:
 Some USB-based watchdogs are not using a serial dongle, but show up as USB HID devices and I don't know what is their protocol. Some USB-based watchdogs are not using a serial dongle, but show up as USB HID devices and I don't know what is their protocol.
  
-This is a script that will generate a Procd service to control one of such USB-serial watchdogs+This is a script that will generate a procd service to control one of such USB-serial watchdogs.
  
-<code bash usb_watchdog>+<code bash> 
 +cat << "EOF" > /etc/usb_watchdog
 #!/bin/sh #!/bin/sh
  
 # Watchdog control script for USB-serial based watchdogs # Watchdog control script for USB-serial based watchdogs
  
-# The command to run the watchdog 160 seconds is+# The command to run the watchdog 160 seconds is:
 # echo -n -e "\x10" > /dev/ttyUSB0 # echo -n -e "\x10" > /dev/ttyUSB0
 # The "x10" is 16 in hexadecimal and will tell the watchdog to run for 160 seconds, setting a higher (or lower) time is possible, # The "x10" is 16 in hexadecimal and will tell the watchdog to run for 160 seconds, setting a higher (or lower) time is possible,
Line 131: Line 85:
  
 usb_serial="$(dmesg | sed -n -e "/\sch341.*\stty/s/^.*\s//p")" usb_serial="$(dmesg | sed -n -e "/\sch341.*\stty/s/^.*\s//p")"
 +cmd="${1:-start}"
  
 if [ -z "${usb_serial}" ] if [ -z "${usb_serial}" ]
Line 138: Line 93:
 fi fi
  
-case "${1}" in+case "${cmd}" in
  
-stop)+(start) 
 +echo "starting usb watchdog service"
  
-touch /tmp/stop_usb_watchdog +while [ ! -f /tmp/stop_usb_watchdog ] 
-exit 0+do 
 +    echo -n -e "\x10" > /dev/"${usb_serial}" 
 +    sleep 30 
 +done 
 +rm /tmp/stop_usb_watchdog 
 + 
 +echo "stopping usb watchdog service"
 ;; ;;
  
-install)+(stop) 
 +touch /tmp/stop_usb_watchdog 
 +;;
  
-cat << "EOF" > /etc/init.d/usb_watchdog+(install) 
 +cat << "EOI" > /etc/init.d/usb_watchdog
 #!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
  
Line 157: Line 122:
 start_service() { start_service() {
     procd_open_instance     procd_open_instance
-    procd_set_param command /bin/sh "/etc/usb_watchdog"+    procd_set_param command /bin/sh /etc/usb_watchdog
     # If process dies sooner than respawn_threshold, it is considered crashed and after 5 retries the service is stopped     # If process dies sooner than respawn_threshold, it is considered crashed and after 5 retries the service is stopped
     procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}     procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
Line 163: Line 128:
 } }
  
-stop_service() +stop_service() { 
-+    /etc/usb_watchdog stop
-    /etc/init.d/usb_watchdog stop+
 } }
-EOF+EOI
  
-chmod +x /etc/init.d/usb_watchdog +cat << "EOI" > /lib/upgrade/keep.d/usb_watchdog
- +
-cat << "EOF" > /lib/upgrade/keep.d/usb_watchdog +
-/etc/usb_watchdog+
 /etc/init.d/usb_watchdog /etc/init.d/usb_watchdog
 /etc/rc.d/ /etc/rc.d/
-EOF+/etc/usb_watchdog 
 +EOI
  
 +chmod +x /etc/init.d/usb_watchdog
 /etc/init.d/usb_watchdog enable /etc/init.d/usb_watchdog enable
 /etc/init.d/usb_watchdog start /etc/init.d/usb_watchdog start
- 
-if grep -q -e "usb_watchdog" /etc/rc.local 
-then sed -i -e "/^exit 0$/i /etc/init.d/usb_watchdog enable" /etc/rc.local 
-fi 
-exit 0 
 ;; ;;
  
-remove) +(remove) 
- +/etc/init.d/usb_watchdog disable 
-rm /lib/upgrade/keep.d/usb_watchdog +/etc/init.d/usb_watchdog stop 
-rm /etc/usb_watchdog +rm -f /etc/init.d/usb_watchdog 
-rm /etc/init.d/usb_watchdog +rm -/etc/usb_watchdog 
-sed -i -e "/^\/etc\/init\.d\/usb_watchdog enable$/d" /etc/rc.local +rm -f /lib/upgrade/keep.d/usb_watchdog
-exit 0+
 ;; ;;
  
 esac esac
- +EOF 
-echo "starting usb watchdog service" +chmod +x /etc/usb_watchdog 
- +/etc/usb_watchdog install
-while [ ! -f /tmp/stop_usb_watchdog ] +
-do +
-    echo -n -e "\x10"/dev/"${usb_serial}" +
-    sleep 30 +
-done +
- +
-rm /tmp/stop_usb_watchdog +
- +
-echo "stopping usb watchdog service"+
 </code> </code>
  
Line 213: Line 161:
  
 <code bash> <code bash>
-wget --no-check-certificate -O /etc/usb_watchdog "https://openwrt.org/_export/code/docs/guide-user/hardware/watchdog?codeblock=6+uclient-fetch -O usb-watchdog.sh "https://openwrt.org/_export/code/docs/guide-user/hardware/watchdog?codeblock=3
-chmod +x /etc/usb_watchdog +. ./usb-watchdog.sh
-/etc/usb_watchdog install+
 </code> </code>
  
  • Last modified: 2023/08/21 09:20
  • by vgaetera