-1

I have C++ app is running on my device which is a bit modified version of Raspberry PI. Application is reading data from a serial port and I need a device to reboot after some particular data is received. I've been wondering about integrating this functionality with watchdog but have no idea how to do it. Maybe there is a possibility to send some signal from my app to watchdog to tell that it's time to reboot?

P.S. Application starts as systemd service.

Iggy
  • 4,767
  • 5
  • 23
  • 34
oodessit
  • 1
  • 4
  • 1
    For me it's not a good idea, because watchdogs normally work the other way round, watchdog triggers reboot when does not hear from some external device for a while. in your case you just have to call a reboot when you receive something, does not seem a big deal. – Marco Jun 14 '19 at 12:30
  • @Marco of course calling reboot was the first thing I thought about. But watchdog sounds much more correctly to me. Isn't it ? – oodessit Jun 14 '19 at 12:36
  • @oodessit `sounds` is not a technical argument. Marco explained how watchdogs are used and he point out that your case do not match this scenario. – Marek R Jun 14 '19 at 12:49

3 Answers3

1

Call

std::system("sudo reboot");
pm101
  • 1,309
  • 10
  • 30
  • 1
    That's the right answer for the problem. However, I wouldn't expect `sudo reboot` to work on most installation since it usually requires entering the password which might not be possible. You can fiddle with `/etc/sudoers` to give right for the given user to reboot passwordless, but that's ugly. – xryl669 Jun 14 '19 at 13:55
  • 1
    Instead use `reboot` directly (this will require running the main app as root). – xryl669 Jun 14 '19 at 13:55
  • 1
    For password less reboot, see [this](https://unix.stackexchange.com/questions/117148/how-can-i-run-reboot-as-a-normal-user-without-needing-to-enter-a-password) – xryl669 Jun 14 '19 at 13:59
0

Why would you do this that way? The reason one uses watchdogs is exactly what Marco described. If a system does not respond the watchdog triggers. Typically this is needed because devices that are lets say turned off do not send anything anymore, therefore you need some kind of trigger to let your system know it should reboot. Here you already get your trigger from the incoming signal therefore the watchdog is redundand. Simply reboot after you have received your data.

NewEyes
  • 407
  • 4
  • 15
0

Watchdog is great if you want your device to reboot autonomously when your software blocks or Is not reachable anymore If that is what you want to achieve watchdog is the right choice.

Marco
  • 1,952
  • 1
  • 17
  • 23