You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

42 lines
1.1 KiB

#!/bin/bash
cd "$(dirname "$0")"
CONTAINER=facti13bot_discord_v2
WGETHOST=https://discord.com
LOGFILE=./upcheck.log
CHECK_CONTAINER="$(docker ps | grep $CONTAINER | wc -l)"
if [ "$CHECK_CONTAINER" == "0" ]; then
echo 'container is not started'
docker compose up -d
exit 0
fi
COUNT=0
MAXPING=30
while [ $COUNT -le $MAXPING ]
do
COUNT=`expr $COUNT + 1`
/usr/bin/docker exec -it $CONTAINER /bin/sh -c 'wget --method=HEAD -O- '$WGETHOST' > /dev/null && exit 0 || exit 1'
if [ $? == 0 ]; then
echo "["$COUNT"]" `date +%Y%m%d.%H%M%S` $? >> $LOGFILE
exit 0
fi
if [ $? == 1 ]; then
echo "["$COUNT"]" `date +%Y%m%d.%H%M%S` $? >> $LOGFILE
if [ $COUNT -ge 29 ]; then
echo "["$COUNT"]" `date +%Y%m%d.%H%M%S` "PING FAIL TOTALY" >> $LOGFILE
docker compose down
docker compose up -d
exit 0
fi
sleep 1
else
echo "["$COUNT"]" `date +%Y%m%d.%H%M%S` $? >> $LOGFILE
exit 0
fi
done