From efd14c76d321d467d8deb8562fbc85b418f6aee6 Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Thu, 23 Jul 2020 23:32:06 -0500 Subject: [PATCH] Improve check in success --- rootfs/standard/etc/systemd/system/www.service | 1 + rootfs/standard/usr/bin/mynode_post_www.sh | 10 ++++++++++ rootfs/standard/var/www/mynode/thread_functions.py | 14 +++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100755 rootfs/standard/usr/bin/mynode_post_www.sh diff --git a/rootfs/standard/etc/systemd/system/www.service b/rootfs/standard/etc/systemd/system/www.service index f1d5c36f..77ce6156 100644 --- a/rootfs/standard/etc/systemd/system/www.service +++ b/rootfs/standard/etc/systemd/system/www.service @@ -16,6 +16,7 @@ Nice=-15 IOAccounting=true IOWeight=2000 ExecStart=/usr/bin/python /var/www/mynode/mynode.py +ExecStartPost=/usr/bin/mynode_post_www.sh User=root Group=root StandardOutput=syslog diff --git a/rootfs/standard/usr/bin/mynode_post_www.sh b/rootfs/standard/usr/bin/mynode_post_www.sh new file mode 100755 index 00000000..5546c213 --- /dev/null +++ b/rootfs/standard/usr/bin/mynode_post_www.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +source /usr/share/mynode/mynode_config.sh + +set -x + +sleep 10s + +# Load webpage once to trigger initial load +curl http://localhost/ diff --git a/rootfs/standard/var/www/mynode/thread_functions.py b/rootfs/standard/var/www/mynode/thread_functions.py index 4535d850..7e6b4779 100644 --- a/rootfs/standard/var/www/mynode/thread_functions.py +++ b/rootfs/standard/var/www/mynode/thread_functions.py @@ -175,10 +175,17 @@ def check_in(): session.proxies['https'] = 'socks5h://localhost:9050' # Check In + fail_count = 0 check_in_success = False while not check_in_success: try: - r = session.post(CHECKIN_URL, data=data, timeout=10) + # Use tor for check in unless there have been tor 10 failures in a row + r = None + if (fail_count+1) % 10 == 0: + r = requests.post(CHECKIN_URL, data=data, timeout=15) + else: + r = session.post(CHECKIN_URL, data=data, timeout=15) + if r.status_code == 200: if r.text == "OK": os.system("printf \"%s | Check In Success: {} \\n\" \"$(date)\" >> /tmp/check_in_status".format(r.text)) @@ -198,8 +205,9 @@ def check_in(): os.system("printf \"%s | Check In Failed. Retrying... Exception {} \\n\" \"$(date)\" >> /tmp/check_in_status".format(e)) if not check_in_success: - # Check in failed, try again in 2 minutes + # Check in failed, try again in 3 minutes os.system("touch /tmp/check_in_error") - time.sleep(120) + time.sleep(180) + fail_count = fail_count + 1 return True \ No newline at end of file