2 Commits 9943c0a44e ... af2e6dbb89

Author SHA1 Message Date
  Fabian Peter Hammerle af2e6dbb89 release v2.1.0 2 years ago
  Fabian Peter Hammerle 3db6b8f2a8 retry $RETRIES times before reporting "offline" state 2 years ago
5 changed files with 21 additions and 5 deletions
  1. 7 1
      CHANGELOG.md
  2. 1 0
      Dockerfile
  3. 1 0
      README.md
  4. 1 0
      docker-compose.yml
  5. 11 4
      monitor.sh

+ 7 - 1
CHANGELOG.md

@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+## [2.1.0] - 2021-07-31
+### Added
+- configure number of retries before reporting "offline" state
+  via environment variable `RETRIES` (default: `0`)
+
 ## [2.0.0] - 2021-04-10
 ### Added
 - support multiple recipients
@@ -27,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [1.0.0] - 2020-01-04
 
-[Unreleased]: https://github.com/fphammerle/docker-onion-service-status-mail/compare/v2.0.0...HEAD
+[Unreleased]: https://github.com/fphammerle/docker-onion-service-status-mail/compare/v2.1.0...HEAD
+[2.1.0]: https://github.com/fphammerle/docker-onion-service-status-mail/compare/v2.0.0...v2.1.0
 [2.0.0]: https://github.com/fphammerle/docker-onion-service-status-mail/compare/v1.0.0...v2.0.0
 [1.0.0]: https://github.com/fphammerle/docker-onion-service-status-mail/tree/v1.0.0

+ 1 - 0
Dockerfile

@@ -19,6 +19,7 @@ ENV TOR_HOST= \
     ONION_SERVICE_PORT= \
     TIMEOUT_SECONDS=4 \
     SLEEP_DURATION=16s \
+    RETRIES=0 \
     MAIL_TO= \
     VERBOSE=
 

+ 1 - 0
README.md

@@ -19,6 +19,7 @@ $ sudo docker run -d --network tor \
     -e TOR_HOST=tor_proxy -e TOR_PORT=9050 \
     -e ONION_SERVICE_HOST=change-me.onion \
     -e ONION_SERVICE_PORT=80 \
+    -e RETRIES=2 \
     -e MAIL_TO=me@example.com,someone@else.com \
     --name onion_service_monitor  \
     fphammerle/onion-service-status-mail

+ 1 - 0
docker-compose.yml

@@ -23,6 +23,7 @@ services:
       ONION_SERVICE_PORT: 80
       # TIMEOUT_SECONDS: 8
       # SLEEP_DURATION: 1m
+      # RETRIES: 4
       MAIL_TO: change.me@domain.tld, another@recipient.com
       #VERBOSE: 1
     volumes:

+ 11 - 4
monitor.sh

@@ -38,6 +38,7 @@ EOF
 )}
 
 last_state=""
+left_retries="$RETRIES"
 while : ; do
     if ! nc -z -w "$TIMEOUT_SECONDS" "$TOR_HOST" "$TOR_PORT"; then
         echo "failed to connect to tor proxy at $TOR_HOST:$TOR_PORT"
@@ -48,12 +49,18 @@ while : ; do
                 send_report online
             fi
             last_state="online"
+            left_retries=$RETRIES
         else
-            if [ "$last_state" == "online" ]; then
-                echo went offline
-                send_report offline
+            if [ $left_retries -le 0 ]; then
+                if [ "$last_state" == "online" ]; then
+                    echo went offline
+                    send_report offline
+                fi
+                last_state="offline"
+            else
+                left_retries=$((left_retries-1))
+                [ ! -z "$VERBOSE" ] && echo "$left_retries retry/ies left"
             fi
-            last_state="offline"
         fi
     fi
     # flush queue