monitoring/monitoring.sh hinzugefügt
This commit is contained in:
parent
d9ff25e04e
commit
ffff9c87ef
|
@ -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
|
Loading…
Reference in New Issue