aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-06-15 17:10:04 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-06-15 17:10:04 +0200
commitf44dc8feb115c531636b8796af27a3f9a6909ca5 (patch)
treeca5ce335dcf69bb32f76b9f3b2d5a8b980642752 /src
parent76bd5cf7b3771864ed54e42aadc5fee57826d32d (diff)
download0tdns-f44dc8feb115c531636b8796af27a3f9a6909ca5.tar.gz
0tdns-f44dc8feb115c531636b8796af27a3f9a6909ca5.zip
appripriately log vpn connection failures
Diffstat (limited to 'src')
-rwxr-xr-xsrc/hourly.py36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/hourly.py b/src/hourly.py
index 155113e..1fd223d 100755
--- a/src/hourly.py
+++ b/src/hourly.py
@@ -71,17 +71,27 @@ with open("/var/log/0tdns.log", "w") as logfile:
connection.close()
parallel_vpns = ztdns_config['parallel_vpns']
- vpn_wrapper_pids = set()
-
+ pids_vpns = {} # map each wrapper pid to id of the vpn it connects to
+
+ def wait_for_wrapper_process():
+ while True:
+ pid, exit_status = waitpid(0, 0)
+ # make sure
+ if pids_vpns.get(pid) is not None:
+ break
+ if exit_status == 2:
+ # this means our perform_queries.py crashed... not good
+ logfile.write('performing queries through vpn {} failed\n'\
+ .format(pids_vpns[pid]))
+ elif exit_status != 0:
+ # vpn server is probably not responding
+ logfile.write('connection to vpn {} failed\n'\
+ .format(pids_vpns[pid]))
+ pids_vpns.pop(pid)
+
for vpn_id, config_hash in vpns:
- if len(vpn_wrapper_pids) == parallel_vpns:
- while True:
- pid, exit_status = waitpid(0, 0)
- if pid in vpn_wrapper_pids:
- break
- if exit_status != 0:
- logfile.write("one of vpn connections failed")
- vpn_wrapper_pids.remove(pid)
+ if len(pids_vpns) == parallel_vpns:
+ wait_for_wrapper_process()
config_path = "/var/lib/0tdns/{}.ovpn".format(config_hash)
physical_ip = get_default_host_address(ztdns_config['host'])
@@ -92,7 +102,7 @@ with open("/var/log/0tdns.log", "w") as logfile:
p = subprocess.Popen([wrapper, config_path, physical_ip,
route_through_veth] + command_in_namespace)
- vpn_wrapper_pids.add(p.pid)
+ pids_vpns[p.pid] = vpn_id
- for pid in vpn_wrapper_pids:
- waitpid(pid, 0)
+ while len(pids_vpns) > 0:
+ wait_for_wrapper_process()
scm?id=51fd92cef46fb658becf3a58a99a34b7331a7840'>gnu: gtkwave: Update to 3.3.104....Tobias Geerinckx-Rice 2020-03-29gnu: nextpnr-ice40: Clean-up description....Efraim Flashner 2020-03-29gnu: nextpnr-ice40: Use a source file-name....Efraim Flashner 2020-03-28Update email address and Savannah handle for Amin Bandali....Amin Bandali 2020-03-22gnu: Add nextpnr-ice40....pinoaffe@airmail.cc 2020-03-22gnu: icestorm: Update to latest revision....pinoaffe@airmail.cc 2020-02-20gnu: fpga.scm: Use git-version and git-file-name where appropriate....Jakub Kądziołka 2020-02-15gnu: abc: Use HTTPS home page....Tobias Geerinckx-Rice 2020-01-22gnu: gtkwave: Update to 3.3.103....Tobias Geerinckx-Rice 2020-01-22gnu: gtkwave: Prefer mirror://sourceforge source URI....Tobias Geerinckx-Rice 2020-01-17Update email address for Amin Bandali....Amin Bandali