The network watchdog and VirtualHub

The network watchdog and VirtualHub

The VirtualHub application emulates a YoctoHub and offers almost the same features. However, one feature was missing: the network watchdog. This watchdog enables YoctoHubs to be rebooted in the event of prolonged loss of network connectivity. This feature is now available in the VirtualHub application. So it's now possible to reboot your computer remotely using VirtualHub, but rest assured, we've provided safeguards.



Before talking about this new feature, you should know that, for obvious security reasons, it is disabled by default. To enable VirtualHub to restart your computer, you need to run it from the command line with specific arguments (see below). VirtualHub's basic behavior remains unchanged.

Network watchdog


The purpose of the network watchdog is to completely reboot the system in the event of prolonged loss of network connectivity from a YoctoHub or VirtualHub.

This feature is designed to unblock the rare cases of network card crashes. On wired network cards, these bugs are virtually non-existent, but on wireless networks, particularly the GSM network, the SIM card and/or network card may be unable to reconnect. In this case, the only solution is to power cycle the network card.

To test network connectivity, hubs and VirtualHub use HTTP callback (on YoctoHubs, NTP requests can also be used to detect loss of connectivity). The network watchdog is therefore useless if no HTTP callback is defined. Indeed, if no callback is set, VirtualHub will not detect a connection error and will never restart the machine. It may therefore be useful to configure an HTTP callback that sends no command and whose sole purpose is to activate the watchdog.

Note that if you stop the server responding to the HTTP callback, the Hubs interpret this as a loss of network connectivity.

The network watchdog configuration panel
The network watchdog configuration panel



You can configure the watchdog delay from the configuration panel, just below the HTTP callback section. A value below 90 seconds disables the watchdog, and a value above 90 seconds enables it. If you need the watchdog, use a delay long enough to ensure that the hubs or VirtualHub have time to establish the connection. Otherwise, you risk having machines and hubs restarting in a loop.

Watchdog actions


On YoctoHubs, the only possible action at the end of the countdown is to restart the module. With VirtualHub, there are three possibilities: log a message, stop execution, or restart the machine.

The choice between these three options is made using the --www_watchdog option. This option takes the keywords log, stop, or reboot as argument.


C:\VirtualHub\windows\amd64>VirtualHub.exe --www_watchdog log
[2024-06-13 09:06:41] (01) Yoctopuce VirtualHub 1.10.61386 (dated Jun 12 2024)
[2024-06-13 09:06:41] (01) Serial is VIRTHUB0-66c7ee53a7
[2024-06-13 09:06:41] (01) load settings from C:\Users\abc\AppData\Roaming\.virtualhub.dat
[2024-06-13 09:06:41] (01) NetworkName is VIRTHUB0-66c7ee
[2024-06-13 09:06:41] (01) LogicalName is not set
[2024-06-13 09:06:41] (01) HTTP server is listening port 4444
[2024-06-13 09:06:46] (02) 07:06:46 Callback: failed to connect [invalid.com]
...
[2024-06-13 09:08:06] (02) 07:08:06 Callback: failed to connect [invalid.com]
[2024-06-13 09:08:11] (01) Network watchdog has expired
....


The log option displays a log message indicating that the watchdog has expired. This is VirtualHub's default behavior. For example, with a 2-minute watchdog, the message "Network watchdog has expired" is logged every two minutes. This doesn't solve any problems, but it does allow you to debug the problem and avoid rebooting a machine when you least expect it.

C:\VirtualHub\windows\amd64>VirtualHub.exe --www_watchdog reboot


The reboot option is the closest to YoctoHub behavior. When the watchdog expires, the machine's OS (Windows, Linux, or macOS) restarts. However, you need to be very careful when using this option. First, make sure that your OS is configured to start VirtualHub automatically. If this is not the case, you won't get very far, as the OS will have restarted, but the VirtualHub application won't be running. For Linux and macOS users, you also need to ensure that the startup script launches VirtualHub with root privileges. Otherwise, the OS blocks the reboot command.

The stop option simply stops VirtualHub execution and returns an error code. This option allows you to restart VirtualHub without completely rebooting the machine's OS. However, the startup script must be configured to restart VirtualHub automatically if the process stops.

For example, under Linux, the Restart=on-failure option restarts the application if it terminates with an error code.

[Unit] Description=Yoctopuce VirtualHub After=network.target [Service] ExecStart=/usr/sbin/VirtualHub --www_watchdog stop -c /etc/vhub.byn Restart=on-failure Type=simple [Install] WantedBy=multi-user.target



Under Windows, you can write a small batch file with the same behavior:

:retry C:\VirtualHub\windows\amd64>VirtualHub.exe --www_watchdog stop if "%ERRORLEVEL%" == "0" goto retry



This option is also useful if you want to write your own code to restart the machine. For example, it may be prudent to cleanly stop other services running on the machine before restarting the OS.


Conclusion


On YoctoHubs, the network watchdog has been present for a very long time, but we were asked if it was possible to add this feature to VirtualHub. Indeed, some people are using Raspberry Pi with GSM network cards and are experiencing exactly the same problems we've had to deal with on our YoctoHubs.

It is possible to add this type of watchdog using third-party applications or by writing your own, but as we already had all the logic in the hubs, we added this functionality to VirtualHub.

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.