30 lines
971 B
Bash
30 lines
971 B
Bash
#!/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
|