From ffff9c87ef6e0ccaebf27a63d123c2a78354ddf4 Mon Sep 17 00:00:00 2001 From: Akiru Date: Thu, 25 Jan 2024 08:35:11 +0000 Subject: [PATCH] =?UTF-8?q?monitoring/monitoring.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitoring/monitoring.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 monitoring/monitoring.sh diff --git a/monitoring/monitoring.sh b/monitoring/monitoring.sh new file mode 100644 index 0000000..84abdbc --- /dev/null +++ b/monitoring/monitoring.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# This script has to be run as systemd service. It checks journalctl output for errors and restarts the bot automatically when they occur too often. + +# Define the regex pattern to search for occurrences of "GrammyError" and "sendMediaGroup" +ERROR_PATTERN="GrammyError.*sendMediaGroup" + +# Initialize the counter for consecutive occurrences +error_count=0 + +# Monitor the journalctl output +journalctl -xe -f | while read line; do + # Check if the line contains the pattern + if echo "$line" | grep -qE "$ERROR_PATTERN"; then + # Increment the error counter + ((error_count++)) + + # Check if the error has occurred 4 times in a row + if [ $error_count -eq 4 ]; then + # Restart the bot service + systemctl restart nyxthebot + # Reset the error counter + error_count=0 + fi + else + # Reset the error counter if the line does not contain the error + error_count=0 + fi +done