From 6937a19a334d2e61b30445661ba64154daedbd5a Mon Sep 17 00:00:00 2001 From: gsd Date: Wed, 16 Oct 2024 21:02:09 +0300 Subject: [PATCH] check fix --- 1 | 6 ++++++ 2 | 6 ++++++ cat | 6 ++++++ echo | 1 + upcheck.sh | 26 +++++++++++++++----------- 5 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 1 create mode 100644 2 create mode 100644 cat create mode 100644 echo diff --git a/1 b/1 new file mode 100644 index 0000000..2fc07fd --- /dev/null +++ b/1 @@ -0,0 +1,6 @@ +PING 8.8.8.8 (8.8.8.8): 56 data bytes +64 bytes from 8.8.8.8: seq=0 ttl=54 time=82.173 ms + +--- 8.8.8.8 ping statistics --- +1 packets transmitted, 1 packets received, 0% packet loss +round-trip min/avg/max = 82.173/82.173/82.173 ms diff --git a/2 b/2 new file mode 100644 index 0000000..0ea9a12 --- /dev/null +++ b/2 @@ -0,0 +1,6 @@ +PING 8.8.8.8 (8.8.8.8): 56 data bytes +64 bytes from 8.8.8.8: seq=0 ttl=54 time=81.366 ms + +--- 8.8.8.8 ping statistics --- +1 packets transmitted, 1 packets received, 0% packet loss +round-trip min/avg/max = 81.366/81.366/81.366 ms diff --git a/cat b/cat new file mode 100644 index 0000000..a75844d --- /dev/null +++ b/cat @@ -0,0 +1,6 @@ +PING 8.8.8.8 (8.8.8.8): 56 data bytes +64 bytes from 8.8.8.8: seq=0 ttl=54 time=81.466 ms + +--- 8.8.8.8 ping statistics --- +1 packets transmitted, 1 packets received, 0% packet loss +round-trip min/avg/max = 81.466/81.466/81.466 ms diff --git a/echo b/echo new file mode 100644 index 0000000..8315eef --- /dev/null +++ b/echo @@ -0,0 +1 @@ +the input device is not a TTY diff --git a/upcheck.sh b/upcheck.sh index 5bbbeb9..485f44a 100755 --- a/upcheck.sh +++ b/upcheck.sh @@ -5,7 +5,7 @@ LOGFILE=./upcheck.log CONTAINER=proxywg_socks_c PINGHOST=8.8.8.8 -CHECK_CONTAINER="$(docker ps | grep $CONTAINER | wc -l)" +CHECK_CONTAINER="$(/usr/bin/docker ps | grep $CONTAINER | wc -l)" if [ "$CHECK_CONTAINER" == "0" ]; then echo "[" $COUNT "]" `date +%Y%m%d.%H%M%S` "CONTAINER FAIL" >> $LOGFILE echo 'container is not started' @@ -19,21 +19,25 @@ MAXPING=30 while [ $COUNT -le $MAXPING ] do COUNT=`expr $COUNT + 1` - RESULT="$(docker exec -it $CONTAINER ping -c 1 -W 1 $PINGHOST > /dev/null && echo 'pass' || echo 'fail')" + /usr/bin/docker exec -it $CONTAINER /bin/sh -c 'ping -c 1 -W 1 '$PINGHOST' > /dev/null && exit 0 || exit 1' - if [ "$RESULT" == "pass" ]; then - echo "[" $COUNT "]" `date +%Y%m%d.%H%M%S` "PING OK" >> $LOGFILE + if [ $? == 0 ]; then + echo "["$COUNT"]" `date +%Y%m%d.%H%M%S` $? >> $LOGFILE exit 0 fi - echo "[" $COUNT "]" `date +%Y%m%d.%H%M%S` "PING FAIL" >> $LOGFILE + if [ $? == 1 ]; then + echo "["$COUNT"]" `date +%Y%m%d.%H%M%S` $? >> $LOGFILE - if [ $COUNT -ge 29 ]; then - #echo 'container is not good' - echo "[" $COUNT "]" `date +%Y%m%d.%H%M%S` "PING FAIL TOTALY" >> $LOGFILE - docker compose down - docker compose up -d + 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 - sleep 1 done