Is it possible to activate the watchdog on any Linux machine?












3















On an Orange Pi Zero running a Raspbian server, it's possible to use the watchdog very easily just by running the command echo 1 > /dev/watchdog as root. The idea is that the system will certainly reboot after some time that this command is executed, so I need to keep repeating this command in a regular interval of time to keep the system on. We can implement a watchdog using cron as root and making it execute the following script on boot:



#!/bin/bash
while [ true ]; do
echo 1 > /dev/watchdog
sleep 5
done


This script works fine on the Orange Pi Zero... However, on my desktop computer running Ubuntu 18.04 the command echo 1 > /dev/watchdog doesn't work at all. Is it possible to activate the watchdog on any device running Linux? Or is it one parameter that needs to be specified on the Kernel while it's compiled?










share|improve this question





























    3















    On an Orange Pi Zero running a Raspbian server, it's possible to use the watchdog very easily just by running the command echo 1 > /dev/watchdog as root. The idea is that the system will certainly reboot after some time that this command is executed, so I need to keep repeating this command in a regular interval of time to keep the system on. We can implement a watchdog using cron as root and making it execute the following script on boot:



    #!/bin/bash
    while [ true ]; do
    echo 1 > /dev/watchdog
    sleep 5
    done


    This script works fine on the Orange Pi Zero... However, on my desktop computer running Ubuntu 18.04 the command echo 1 > /dev/watchdog doesn't work at all. Is it possible to activate the watchdog on any device running Linux? Or is it one parameter that needs to be specified on the Kernel while it's compiled?










    share|improve this question



























      3












      3








      3








      On an Orange Pi Zero running a Raspbian server, it's possible to use the watchdog very easily just by running the command echo 1 > /dev/watchdog as root. The idea is that the system will certainly reboot after some time that this command is executed, so I need to keep repeating this command in a regular interval of time to keep the system on. We can implement a watchdog using cron as root and making it execute the following script on boot:



      #!/bin/bash
      while [ true ]; do
      echo 1 > /dev/watchdog
      sleep 5
      done


      This script works fine on the Orange Pi Zero... However, on my desktop computer running Ubuntu 18.04 the command echo 1 > /dev/watchdog doesn't work at all. Is it possible to activate the watchdog on any device running Linux? Or is it one parameter that needs to be specified on the Kernel while it's compiled?










      share|improve this question
















      On an Orange Pi Zero running a Raspbian server, it's possible to use the watchdog very easily just by running the command echo 1 > /dev/watchdog as root. The idea is that the system will certainly reboot after some time that this command is executed, so I need to keep repeating this command in a regular interval of time to keep the system on. We can implement a watchdog using cron as root and making it execute the following script on boot:



      #!/bin/bash
      while [ true ]; do
      echo 1 > /dev/watchdog
      sleep 5
      done


      This script works fine on the Orange Pi Zero... However, on my desktop computer running Ubuntu 18.04 the command echo 1 > /dev/watchdog doesn't work at all. Is it possible to activate the watchdog on any device running Linux? Or is it one parameter that needs to be specified on the Kernel while it's compiled?







      linux-kernel raspbian watchdog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 22 mins ago







      Rafael Muynarsk

















      asked Dec 31 '18 at 20:09









      Rafael MuynarskRafael Muynarsk

      422615




      422615






















          2 Answers
          2






          active

          oldest

          votes


















          4














          There are two types of watchdog; hardware and software. On the Orange Pi the SOC chip provides a hardware watchdog. If initialised then it needs to be pinged every so often, otherwise it performs a board reset.



          However not many desktops have hardware watchdogs, so the kernel provides a software version. Now the kernel will try and keep track, and force a reboot. This isn't as good as a hardware watchdog because if the kernel, itself, breaks then nothing will trigger the reset. But it works.



          The software watchdog can be initialised by loading the softdog module



          % modprobe softdog
          % dmesg | tail -1
          [ 120.573945] softdog: Software Watchdog Timer: 0.08 initialized. soft_noboot=0 soft_margin=60 sec soft_panic=0 (nowayout=0)


          We can see this has a 60 second timeout by default.



          If I then do



          % echo > /dev/watchdog
          % dmesg | tail -1
          [ 154.514976] watchdog: watchdog0: watchdog did not stop!


          We can see the watchdog hadn't timed out.



          I then leave the machine idle for a minute and on the console I see



          [  214.624112] softdog: Initiating system reboot


          and the OS reboots.






          share|improve this answer
























          • Many desktops, laptops and servers include hardware watchdogs, often in their Super-I/O chips, or in their PCH; see the various “wdt” modules in the kernel.

            – Stephen Kitt
            Dec 31 '18 at 20:39











          • @StephenHarris Can I assume that when the command echo > /dev/watchdog doesn't work at first it's because there's no hardware watchdog for that device? Or there's still the possibility that I need to activate the hardware watchdog before using it?

            – Rafael Muynarsk
            Dec 31 '18 at 20:45






          • 1





            If /dev/watchdog doesn't exist (or isn't a character device) and you know your hardware has a watchdog, then you may need to modprobe the relevant hardware driver... Modern distro's will try to load this automatically, but you may have an edge-case. None of my machines have a /dev/watchdog entry :-(

            – Stephen Harris
            Dec 31 '18 at 20:48








          • 1





            “Many”, not “all” ;-). My last two personal PCs (2003, 2013) have supported iTCO_wdt, and all my work PCs for the last decade or so have supported one driver or another, but it isn’t loaded automatically; as you mention, in many cases the relevant module needs to be loaded manually, and sometimes the firmware setup has to be configured appropriately too (and sometimes a jumper must be moved on the main board).

            – Stephen Kitt
            Dec 31 '18 at 21:33






          • 1





            @Rafael the BIOS or UEFI setup on a PC.

            – Stephen Kitt
            Dec 31 '18 at 21:38



















          1














          The I/O redirection closes the watchdog file handle after writing the 1. Depending on how the watchdog device is configured, closing the file handle can also disable the watchdog.



          Try



          exec 3>/dev/watchdog
          echo 1 >&3


          This will keep the watchdog device open in the current shell, so the timer will not be stopped.



          Most people run a dedicated watchdog daemon rather than using cron; this daemon runs a list of checks before resetting the timer, so the machine also reboots if tests fail. This could be used to verify that a database service actually processes queries, while regular service monitoring would only verify that the process is running.






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491814%2fis-it-possible-to-activate-the-watchdog-on-any-linux-machine%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            There are two types of watchdog; hardware and software. On the Orange Pi the SOC chip provides a hardware watchdog. If initialised then it needs to be pinged every so often, otherwise it performs a board reset.



            However not many desktops have hardware watchdogs, so the kernel provides a software version. Now the kernel will try and keep track, and force a reboot. This isn't as good as a hardware watchdog because if the kernel, itself, breaks then nothing will trigger the reset. But it works.



            The software watchdog can be initialised by loading the softdog module



            % modprobe softdog
            % dmesg | tail -1
            [ 120.573945] softdog: Software Watchdog Timer: 0.08 initialized. soft_noboot=0 soft_margin=60 sec soft_panic=0 (nowayout=0)


            We can see this has a 60 second timeout by default.



            If I then do



            % echo > /dev/watchdog
            % dmesg | tail -1
            [ 154.514976] watchdog: watchdog0: watchdog did not stop!


            We can see the watchdog hadn't timed out.



            I then leave the machine idle for a minute and on the console I see



            [  214.624112] softdog: Initiating system reboot


            and the OS reboots.






            share|improve this answer
























            • Many desktops, laptops and servers include hardware watchdogs, often in their Super-I/O chips, or in their PCH; see the various “wdt” modules in the kernel.

              – Stephen Kitt
              Dec 31 '18 at 20:39











            • @StephenHarris Can I assume that when the command echo > /dev/watchdog doesn't work at first it's because there's no hardware watchdog for that device? Or there's still the possibility that I need to activate the hardware watchdog before using it?

              – Rafael Muynarsk
              Dec 31 '18 at 20:45






            • 1





              If /dev/watchdog doesn't exist (or isn't a character device) and you know your hardware has a watchdog, then you may need to modprobe the relevant hardware driver... Modern distro's will try to load this automatically, but you may have an edge-case. None of my machines have a /dev/watchdog entry :-(

              – Stephen Harris
              Dec 31 '18 at 20:48








            • 1





              “Many”, not “all” ;-). My last two personal PCs (2003, 2013) have supported iTCO_wdt, and all my work PCs for the last decade or so have supported one driver or another, but it isn’t loaded automatically; as you mention, in many cases the relevant module needs to be loaded manually, and sometimes the firmware setup has to be configured appropriately too (and sometimes a jumper must be moved on the main board).

              – Stephen Kitt
              Dec 31 '18 at 21:33






            • 1





              @Rafael the BIOS or UEFI setup on a PC.

              – Stephen Kitt
              Dec 31 '18 at 21:38
















            4














            There are two types of watchdog; hardware and software. On the Orange Pi the SOC chip provides a hardware watchdog. If initialised then it needs to be pinged every so often, otherwise it performs a board reset.



            However not many desktops have hardware watchdogs, so the kernel provides a software version. Now the kernel will try and keep track, and force a reboot. This isn't as good as a hardware watchdog because if the kernel, itself, breaks then nothing will trigger the reset. But it works.



            The software watchdog can be initialised by loading the softdog module



            % modprobe softdog
            % dmesg | tail -1
            [ 120.573945] softdog: Software Watchdog Timer: 0.08 initialized. soft_noboot=0 soft_margin=60 sec soft_panic=0 (nowayout=0)


            We can see this has a 60 second timeout by default.



            If I then do



            % echo > /dev/watchdog
            % dmesg | tail -1
            [ 154.514976] watchdog: watchdog0: watchdog did not stop!


            We can see the watchdog hadn't timed out.



            I then leave the machine idle for a minute and on the console I see



            [  214.624112] softdog: Initiating system reboot


            and the OS reboots.






            share|improve this answer
























            • Many desktops, laptops and servers include hardware watchdogs, often in their Super-I/O chips, or in their PCH; see the various “wdt” modules in the kernel.

              – Stephen Kitt
              Dec 31 '18 at 20:39











            • @StephenHarris Can I assume that when the command echo > /dev/watchdog doesn't work at first it's because there's no hardware watchdog for that device? Or there's still the possibility that I need to activate the hardware watchdog before using it?

              – Rafael Muynarsk
              Dec 31 '18 at 20:45






            • 1





              If /dev/watchdog doesn't exist (or isn't a character device) and you know your hardware has a watchdog, then you may need to modprobe the relevant hardware driver... Modern distro's will try to load this automatically, but you may have an edge-case. None of my machines have a /dev/watchdog entry :-(

              – Stephen Harris
              Dec 31 '18 at 20:48








            • 1





              “Many”, not “all” ;-). My last two personal PCs (2003, 2013) have supported iTCO_wdt, and all my work PCs for the last decade or so have supported one driver or another, but it isn’t loaded automatically; as you mention, in many cases the relevant module needs to be loaded manually, and sometimes the firmware setup has to be configured appropriately too (and sometimes a jumper must be moved on the main board).

              – Stephen Kitt
              Dec 31 '18 at 21:33






            • 1





              @Rafael the BIOS or UEFI setup on a PC.

              – Stephen Kitt
              Dec 31 '18 at 21:38














            4












            4








            4







            There are two types of watchdog; hardware and software. On the Orange Pi the SOC chip provides a hardware watchdog. If initialised then it needs to be pinged every so often, otherwise it performs a board reset.



            However not many desktops have hardware watchdogs, so the kernel provides a software version. Now the kernel will try and keep track, and force a reboot. This isn't as good as a hardware watchdog because if the kernel, itself, breaks then nothing will trigger the reset. But it works.



            The software watchdog can be initialised by loading the softdog module



            % modprobe softdog
            % dmesg | tail -1
            [ 120.573945] softdog: Software Watchdog Timer: 0.08 initialized. soft_noboot=0 soft_margin=60 sec soft_panic=0 (nowayout=0)


            We can see this has a 60 second timeout by default.



            If I then do



            % echo > /dev/watchdog
            % dmesg | tail -1
            [ 154.514976] watchdog: watchdog0: watchdog did not stop!


            We can see the watchdog hadn't timed out.



            I then leave the machine idle for a minute and on the console I see



            [  214.624112] softdog: Initiating system reboot


            and the OS reboots.






            share|improve this answer













            There are two types of watchdog; hardware and software. On the Orange Pi the SOC chip provides a hardware watchdog. If initialised then it needs to be pinged every so often, otherwise it performs a board reset.



            However not many desktops have hardware watchdogs, so the kernel provides a software version. Now the kernel will try and keep track, and force a reboot. This isn't as good as a hardware watchdog because if the kernel, itself, breaks then nothing will trigger the reset. But it works.



            The software watchdog can be initialised by loading the softdog module



            % modprobe softdog
            % dmesg | tail -1
            [ 120.573945] softdog: Software Watchdog Timer: 0.08 initialized. soft_noboot=0 soft_margin=60 sec soft_panic=0 (nowayout=0)


            We can see this has a 60 second timeout by default.



            If I then do



            % echo > /dev/watchdog
            % dmesg | tail -1
            [ 154.514976] watchdog: watchdog0: watchdog did not stop!


            We can see the watchdog hadn't timed out.



            I then leave the machine idle for a minute and on the console I see



            [  214.624112] softdog: Initiating system reboot


            and the OS reboots.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 31 '18 at 20:30









            Stephen HarrisStephen Harris

            25.5k24477




            25.5k24477













            • Many desktops, laptops and servers include hardware watchdogs, often in their Super-I/O chips, or in their PCH; see the various “wdt” modules in the kernel.

              – Stephen Kitt
              Dec 31 '18 at 20:39











            • @StephenHarris Can I assume that when the command echo > /dev/watchdog doesn't work at first it's because there's no hardware watchdog for that device? Or there's still the possibility that I need to activate the hardware watchdog before using it?

              – Rafael Muynarsk
              Dec 31 '18 at 20:45






            • 1





              If /dev/watchdog doesn't exist (or isn't a character device) and you know your hardware has a watchdog, then you may need to modprobe the relevant hardware driver... Modern distro's will try to load this automatically, but you may have an edge-case. None of my machines have a /dev/watchdog entry :-(

              – Stephen Harris
              Dec 31 '18 at 20:48








            • 1





              “Many”, not “all” ;-). My last two personal PCs (2003, 2013) have supported iTCO_wdt, and all my work PCs for the last decade or so have supported one driver or another, but it isn’t loaded automatically; as you mention, in many cases the relevant module needs to be loaded manually, and sometimes the firmware setup has to be configured appropriately too (and sometimes a jumper must be moved on the main board).

              – Stephen Kitt
              Dec 31 '18 at 21:33






            • 1





              @Rafael the BIOS or UEFI setup on a PC.

              – Stephen Kitt
              Dec 31 '18 at 21:38



















            • Many desktops, laptops and servers include hardware watchdogs, often in their Super-I/O chips, or in their PCH; see the various “wdt” modules in the kernel.

              – Stephen Kitt
              Dec 31 '18 at 20:39











            • @StephenHarris Can I assume that when the command echo > /dev/watchdog doesn't work at first it's because there's no hardware watchdog for that device? Or there's still the possibility that I need to activate the hardware watchdog before using it?

              – Rafael Muynarsk
              Dec 31 '18 at 20:45






            • 1





              If /dev/watchdog doesn't exist (or isn't a character device) and you know your hardware has a watchdog, then you may need to modprobe the relevant hardware driver... Modern distro's will try to load this automatically, but you may have an edge-case. None of my machines have a /dev/watchdog entry :-(

              – Stephen Harris
              Dec 31 '18 at 20:48








            • 1





              “Many”, not “all” ;-). My last two personal PCs (2003, 2013) have supported iTCO_wdt, and all my work PCs for the last decade or so have supported one driver or another, but it isn’t loaded automatically; as you mention, in many cases the relevant module needs to be loaded manually, and sometimes the firmware setup has to be configured appropriately too (and sometimes a jumper must be moved on the main board).

              – Stephen Kitt
              Dec 31 '18 at 21:33






            • 1





              @Rafael the BIOS or UEFI setup on a PC.

              – Stephen Kitt
              Dec 31 '18 at 21:38

















            Many desktops, laptops and servers include hardware watchdogs, often in their Super-I/O chips, or in their PCH; see the various “wdt” modules in the kernel.

            – Stephen Kitt
            Dec 31 '18 at 20:39





            Many desktops, laptops and servers include hardware watchdogs, often in their Super-I/O chips, or in their PCH; see the various “wdt” modules in the kernel.

            – Stephen Kitt
            Dec 31 '18 at 20:39













            @StephenHarris Can I assume that when the command echo > /dev/watchdog doesn't work at first it's because there's no hardware watchdog for that device? Or there's still the possibility that I need to activate the hardware watchdog before using it?

            – Rafael Muynarsk
            Dec 31 '18 at 20:45





            @StephenHarris Can I assume that when the command echo > /dev/watchdog doesn't work at first it's because there's no hardware watchdog for that device? Or there's still the possibility that I need to activate the hardware watchdog before using it?

            – Rafael Muynarsk
            Dec 31 '18 at 20:45




            1




            1





            If /dev/watchdog doesn't exist (or isn't a character device) and you know your hardware has a watchdog, then you may need to modprobe the relevant hardware driver... Modern distro's will try to load this automatically, but you may have an edge-case. None of my machines have a /dev/watchdog entry :-(

            – Stephen Harris
            Dec 31 '18 at 20:48







            If /dev/watchdog doesn't exist (or isn't a character device) and you know your hardware has a watchdog, then you may need to modprobe the relevant hardware driver... Modern distro's will try to load this automatically, but you may have an edge-case. None of my machines have a /dev/watchdog entry :-(

            – Stephen Harris
            Dec 31 '18 at 20:48






            1




            1





            “Many”, not “all” ;-). My last two personal PCs (2003, 2013) have supported iTCO_wdt, and all my work PCs for the last decade or so have supported one driver or another, but it isn’t loaded automatically; as you mention, in many cases the relevant module needs to be loaded manually, and sometimes the firmware setup has to be configured appropriately too (and sometimes a jumper must be moved on the main board).

            – Stephen Kitt
            Dec 31 '18 at 21:33





            “Many”, not “all” ;-). My last two personal PCs (2003, 2013) have supported iTCO_wdt, and all my work PCs for the last decade or so have supported one driver or another, but it isn’t loaded automatically; as you mention, in many cases the relevant module needs to be loaded manually, and sometimes the firmware setup has to be configured appropriately too (and sometimes a jumper must be moved on the main board).

            – Stephen Kitt
            Dec 31 '18 at 21:33




            1




            1





            @Rafael the BIOS or UEFI setup on a PC.

            – Stephen Kitt
            Dec 31 '18 at 21:38





            @Rafael the BIOS or UEFI setup on a PC.

            – Stephen Kitt
            Dec 31 '18 at 21:38













            1














            The I/O redirection closes the watchdog file handle after writing the 1. Depending on how the watchdog device is configured, closing the file handle can also disable the watchdog.



            Try



            exec 3>/dev/watchdog
            echo 1 >&3


            This will keep the watchdog device open in the current shell, so the timer will not be stopped.



            Most people run a dedicated watchdog daemon rather than using cron; this daemon runs a list of checks before resetting the timer, so the machine also reboots if tests fail. This could be used to verify that a database service actually processes queries, while regular service monitoring would only verify that the process is running.






            share|improve this answer




























              1














              The I/O redirection closes the watchdog file handle after writing the 1. Depending on how the watchdog device is configured, closing the file handle can also disable the watchdog.



              Try



              exec 3>/dev/watchdog
              echo 1 >&3


              This will keep the watchdog device open in the current shell, so the timer will not be stopped.



              Most people run a dedicated watchdog daemon rather than using cron; this daemon runs a list of checks before resetting the timer, so the machine also reboots if tests fail. This could be used to verify that a database service actually processes queries, while regular service monitoring would only verify that the process is running.






              share|improve this answer


























                1












                1








                1







                The I/O redirection closes the watchdog file handle after writing the 1. Depending on how the watchdog device is configured, closing the file handle can also disable the watchdog.



                Try



                exec 3>/dev/watchdog
                echo 1 >&3


                This will keep the watchdog device open in the current shell, so the timer will not be stopped.



                Most people run a dedicated watchdog daemon rather than using cron; this daemon runs a list of checks before resetting the timer, so the machine also reboots if tests fail. This could be used to verify that a database service actually processes queries, while regular service monitoring would only verify that the process is running.






                share|improve this answer













                The I/O redirection closes the watchdog file handle after writing the 1. Depending on how the watchdog device is configured, closing the file handle can also disable the watchdog.



                Try



                exec 3>/dev/watchdog
                echo 1 >&3


                This will keep the watchdog device open in the current shell, so the timer will not be stopped.



                Most people run a dedicated watchdog daemon rather than using cron; this daemon runs a list of checks before resetting the timer, so the machine also reboots if tests fail. This could be used to verify that a database service actually processes queries, while regular service monitoring would only verify that the process is running.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 1 at 5:02









                Simon RichterSimon Richter

                2,4991113




                2,4991113






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491814%2fis-it-possible-to-activate-the-watchdog-on-any-linux-machine%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Loup dans la culture

                    How to solve the problem of ntp “Unable to contact time server” from KDE?

                    ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux