From f4799387ea301fa7e339c7a3e561890e33fb4d06 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Sun, 28 Apr 2024 10:47:23 +0200 Subject: [PATCH] Create throttlescript --- birdnet-pi/etc/cron.hourly/throttlescript | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 birdnet-pi/etc/cron.hourly/throttlescript diff --git a/birdnet-pi/etc/cron.hourly/throttlescript b/birdnet-pi/etc/cron.hourly/throttlescript new file mode 100644 index 000000000..a5695fb3e --- /dev/null +++ b/birdnet-pi/etc/cron.hourly/throttlescript @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Stop the recordings while the analysis catches up https://github.com/mcguirepr89/BirdNET-Pi/issues/393#issuecomment-1166445710 +# +source /etc/birdnet/birdnet.conf +srv="birdnet_recording" +analyzing_now="." +counter=10 +while [ 1 ];do + sleep 61 + if [ $counter -le 0 ];then + latest=$(cat "$HOME"/BirdNET-Pi/analyzing_now.txt) + if [ "$latest" = "$analyzing_now" ];then + echo "$(date) WARNING no change in analyzing_now for 10 iterations, restarting services" + "$HOME"/BirdNET-Pi/scripts/restart_services.sh + fi + counter=10 + analyzing_now=$(cat "$HOME"/BirdNET-Pi/analyzing_now.txt) + fi + if [ -z "${RTSP_STREAM}" ];then + ingest_dir=${RECS_DIR}/$(date +"%B-%Y/%d-%A") + mkdir -p $ingest_dir + else + ingest_dir=$RECS_DIR/StreamData + fi + wavs=$(ls ${ingest_dir}/*.wav | wc -l) + if [ $(systemctl --state=active | grep $srv | wc -l) -eq 0 ];then + state="inactive" + else + state="active" + fi + echo "$(date) INFO ${wavs} wav files waiting in ${ingest_dir}, $srv state is $state" + if [ $wavs -gt 100 -a $state = "active" ];then + sudo systemctl stop $srv + echo "$(date) WARNING stopped $srv service" + elif [ $wavs -le 100 -a $state = "inactive" ];then + sudo systemctl start $srv + echo "$(date) INFO started $srv service" + fi + ((counter-=1)) +done