Skip to content

Instantly share code, notes, and snippets.

@KEINOS
Last active March 13, 2024 17:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KEINOS/bbd158a0b56606e5c54965b65ae34b64 to your computer and use it in GitHub Desktop.
Save KEINOS/bbd158a0b56606e5c54965b65ae34b64 to your computer and use it in GitHub Desktop.
[NanoPi NEO2] Cronjob example to reboot Armbian machine by detecting the CPU temperature.

Auto Rebooting NanoPi NEO2 NAS Before Crash

This gist explains how to reboot the NanoPi NEO2 NAS before the CPU temperature rises too high and the device crashes.

Cron Job Setting Example

$ sudo crontab -l
# Check CPU temperature every 30 min (reboot if over 70°C)
*/30 * * * * /root/cron_jobs/onheat_reboot.sh > /root/cron_jobs/onheat_reboot.log 2>&1

References

DIY NAS Server with 1-bay NAS Dock & NEO2

The 1-bay NAS Dock is an expansion board which can be used to connect an external hard disk to a NanoPi NEO2.It uses JSM568 USB3.0 to SATA IC and communicates with a NanoPi NEO2 via USB interface. It works with a 2.5" SATA hard disk.It uses TI's DC-DC chipset to convert a 12V input to 5V. It has a power switch for users to turn on/off the device.It supports an onboard RTC battery. FriendlyElecmigrated mainline Linux-4.11 kernel and Debian-Jessie with OpenMediaVault. Together with FriendlyElec's customized aluminum case you can quickly assemble a storage server. Here is a hardware setup : 1-bay NAS Dock v1.2 for NanoPi NEO/NEO2

#!/bin/bash
# This cronjob script reboots the NanoPi NEO2 + Armbian computer when the CPU temperature rises above 70°C.
# This script aims to work on 1-bay NAS Kit v1.2 for NanoPi NEO2
HOME="/root"
. /root/.bashrc
set -eu
DEBIAN_FRONTEND=noninteractive
# Include functions:
# getboardtemp()
# batteryinfo()
# ambienttemp()
source /usr/lib/armbian/armbian-allwinner-battery
CPU_TEMP_LIMIT=70
CPU_TEMP_OFFSET=0
getboardtemp
echo "CPU Temp: ${board_temp}℃" "$(date)"
if [[ ($board_temp > $CPU_TEMP_LIMIT) ]]; then
echo "CPU Temperature over ${CPU_TEMP_LIMIT}°C detected. Rebooting."
sudo reboot
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment