forked from pinks/eris
1
0
Fork 0

monitoring/monitoring.sh hinzugefügt

This commit is contained in:
Akiru 2024-01-25 08:35:11 +00:00
parent d9ff25e04e
commit ffff9c87ef
1 changed files with 29 additions and 0 deletions

29
monitoring/monitoring.sh Normal file
View File

@ -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