Skip to content

Instantly share code, notes, and snippets.

@highemerly
Last active November 13, 2023 14:52
Show Gist options
  • Save highemerly/2e790b6285d6d830e2506839ef3158d6 to your computer and use it in GitHub Desktop.
Save highemerly/2e790b6285d6d830e2506839ef3158d6 to your computer and use it in GitHub Desktop.
monitor-redis-for-mastodon-streaming.sh
#!/bin/bash
LOGFILES="/var/log/redis/redis-server.log"
# LOGFILES="/home/highemerly/dummy-redis-server.log"
declare -A last_restart
restart_streaming() {
ssh highemerly@$1 -o StrictHostKeyChecking=no -i /home/highemerly/.ssh/id_rsa "cd mastodon && docker compose restart streaming"
}
ip_check() {
ping $1 -c 1 -W 2 >> /dev/null
if [ $? = "0" ]; then
echo "yes"
else
echo "no"
fi
}
action() {
while read i
do
echo $i | grep "unauth mbulk count" >> /dev/null
if [ $? = "0" ];then
ipaddr=`echo $i | grep "unauth mbulk count" | awk '{print $15}' | sed -e "s/addr=\([0-9]*.[0-9]*.[0-9]*.[0-9]*\)\:[0-9]*/\1/"`
echo "streaming-reboot-required: "$ipaddr
is_alive_ipaddress=`ip_check ${ipaddr}`
if [ $is_alive_ipaddress = "yes" ]; then
now=`date +%s`
last=${last_restart[$ipaddr]}
if [ ${#last} = "0" ]; then
last=0
fi
if [ $(( $now - $last )) -lt 3 ]; then
sleep $(( 3 - $now + $last ))
fi
restart_streaming $ipaddr
sudo -u highemerly /usr/bin/python3 toot.py $ipaddr
last_restart[$ipaddr]=`date +%s`
fi
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment