diff --git a/upcheck.sh b/upcheck.sh new file mode 100644 index 0000000..25e6ad3 --- /dev/null +++ b/upcheck.sh @@ -0,0 +1,42 @@ +#!/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 \ No newline at end of file