Computer

Raspberry Pi always on? Here are the things you need to know

Raspberry Pi always on?  Here are the things you need to know

Raspberry Pi Foundation

The very popular single-board computer Raspberry Pi it is a real point of reference for a large number of projects and application fields. When using the raspberry symbol card as a router, media server, to enable IoT functionality, as a NAS server, to manage cameras, as a VPN server and so on, it is essential to ensure that the device remains constantly onwithout highlighting long-term problems.

Software engineer Chris Dzombak highlighted some interesting points that anyone who keeps a Raspberry Pi on all the time absolutely needs to take into due consideration.

Raspberry Pi: Monitor connection status

If you use a Raspberry Pi board for a long period of time, without ever turning off the device, the network connection it could fail for any reason. Some might smile at the fact of using a Raspberry Pi to manage applications mission critical: in reality, throughout its long history, Raspberry Pi has stood out not only for its flexibility and versatility but also for its intrinsic reliability.

In order to make sure that Raspberry Pi is always operationalthe suggestion is to prepare a mechanism that periodically sends ping requests to the card, notifying the administrator when none arrives answer (it would mean that the card is offline, turned off or otherwise unreachable).

There are different ways to send ping on a periodic basis. One of the possible choices, however, is the network monitoring tool Uptime Againopen source and publicly available in the correspondent repository GitHub.

Update Kuma, Raspberry Pi ping check

Pay attention to the WiFi connection

If your Raspberry Pi was connected to the network via a Wifi connection there really is a multitude of things that could suddenly stop working.

The wifi-check.sh script is designed to periodically check the operation of WiFi on a Raspberry Pi and restart the WiFi interface or the entire device if the connection is not stable.

The main function of wifi-check.sh is to periodically check the connection quality WiFi and take corrective measures in case of any problems.

The code, first of all, disables the low power consumption mode of the WiFi chip; subsequently, the script checks whether the intervention had resolved the problem. In case of failure, the script takes a series of more drastic measures.

The author suggests placing the script, for example, in the directory /usr/local/bin/wifi-check.sh. To run it periodically, you can set the use of flock: in this way only onescript instance is performed. By placing the following code in the file /etc/cron.d/wifi-checkit can be exploited cron to start the script on a periodic basis:

*  *  *  *  *  root  flock -x -n -E 0 /tmp/wifi-check.lock env PING_TARGET=192.168.1.1 WLAN_IF=wlan0 /usr/local/bin/wifi-check.sh

In the example, the local IP 192.168.1.1 corresponds to the router address. Obviously, you need to deactivate the task set with cron during Raspberry Pi maintenance tasks or applying updates.

Automatic system restart

I services systemd they are a basic concept within the GNU/Linux operating systems. Systemd is a management and initialization system that provides a framework for controlling system processes and services during startup and operation of the operating system.

In case of service shutdown, for example when any anomaly occurs, systemd services can be restarted automatically by setting the option Restart.

Depending on systemd settingsit is for example possible to configure the Raspberry Pi so that it automatically restarts the system if service restoration fails several times consecutively.

This code published on GitHub by Dzombak allows for example to configure the restart of the entire Raspberry Pi if the specified service stops several times in a row. Let’s look at this systemd configuration in more detail:

  • After=network.target: Specifies that the service should start after the network is fully operational. This ensures that the service has access to the network when started.
  • StartLimitAction=reboot: Indicates what to do if you experience repeated failures to start the service. In this case, if the service fails to start more than 8 times within 120 seconds, the system will proceed with a reboot.
  • StartLimitIntervalSec=120: Specifies the time interval within which failed startups are counted (120 seconds).
  • StartLimitBurst=8: Specifies the maximum number of startup attempts allowed during the specified time interval (8 attempts).

The section [Service]and in particular the directive ExecStart, specify the command that systemd must execute to start the service. In the example shared by Dzombak, the systemd code appears to trigger a logger environmental that records a series of values ​​and sends them to a database.

Use a quality power supply and microSD

When you decide to use a Raspberry Pi for any purpose over rather large time windows, the use of a power supply low power or poor quality may cause theinstability of the system and its shutdown.

If you have difficulty choosing the most recommended power supply, it is best to refer to the official Raspberry Pi device. By acting on the drop-down menu, you can get the power supply that Raspberry Pi recommends for each board model.

In the case of cards Raspberry Pi 4, the foundation suggested using a 5V/3A power supply. With the most recent version, however, we have moved on to the more stringent requirement of a 5V/5A power supply, especially essential if you plan to connect USB devices and SSDs to the Raspberry Pi 5 board.

The microSD card and swapping capabilities

It goes without saying that the choice of microSD to insert into the Raspberry Pi slot plays a fundamental role. Since many things happen when booting the Raspberry Pi reading and writing operationsthe use of a microSD low quality may not offer such long life.

At every reboot, it might make sense to set up a file system check: sure, the boot procedure might take a little longer to complete, but you have the opportunity to detect any anomalous behavior before it becomes a real problem.

The capacity of the microSD should also be at least double the overall capacity required by the operating system and the applications you plan to run. In this way it is usually possible to help increase the life of the storage medium.

After an installation of Raspberry Pi OS, the operating system automatically allocates a certain amount of space for swap activities on the SD card. The swap (which Windows calls a paging file) is a temporary storage space used by the system when RAM memory is used to its maximum capacity.

If the system does not need to do swappingyou can disable it completely by running the following commands:

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo update-rc.d dphys-swapfile remove

If you are certain that you do not want to re-enable swap in the future, you can completely remove the functionality using the following statement:

sudo apt purge dphys-swapfile -y

However, if the system requires swapping, Dzombak recommends using one USB pendrive economical to avoid damaging the SD card, as explained in the technical document Stop using the Raspberry Pi’s SD card for swap.

Disable services and software components that you do not use

Ultimately, concludes Dzombak, it could make sense turn off daily updates. Applying updates is useful but on Raspberry Pis isolated from the Internet connection, whose reliability is a priority, it may be reasonable to avoid automatic changes without user supervision. The following commands allow you to disable daily updates applied to the Raspberry Pi:

sudo systemctl mask apt-daily-upgrade
sudo systemctl mask apt-daily
sudo systemctl disable apt-daily-upgrade.timer
sudo systemctl disable apt-daily.timer

If you do not use 2G/3G/4G modems, you can remove the software component ModemManager. Similarly, if you are not using Bluetooth, you can disable the related services and remove the associated software:

sudo apt remove --purge modemmanager
sudo apt autoremove --purge
sudo systemctl disable bluetooth.service
sudo systemctl disable hciuart.service
sudo apt remove --purge bluez
sudo apt autoremove --purge

The next command, however, helps identify…

Leave a Reply

Your email address will not be published. Required fields are marked *