aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-06-15 16:25:00 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-06-15 16:25:00 +0200
commit01464c698df4df619a192474d1de8ff62e4e5d7a (patch)
tree5ae2ad9f0010252b6417ea524b13202b5f0e8c59 /src
parenteaf411175906eebaf8bb4411c9232b054f7222bd (diff)
download0tdns-01464c698df4df619a192474d1de8ff62e4e5d7a.tar.gz
0tdns-01464c698df4df619a192474d1de8ff62e4e5d7a.zip
specify number of simultaneous vpn connections in config file
Diffstat (limited to 'src')
-rwxr-xr-xsrc/hourly.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/hourly.py b/src/hourly.py
index 3aa821d..155113e 100755
--- a/src/hourly.py
+++ b/src/hourly.py
@@ -2,7 +2,7 @@
from sys import argv
import subprocess
-from os import path
+from os import path, waitpid
from time import gmtime, strftime, sleep
# our own module used by several scripts in the project
@@ -70,9 +70,19 @@ with open("/var/log/0tdns.log", "w") as logfile:
cursor.close()
connection.close()
- subprocesses = []
+ parallel_vpns = ztdns_config['parallel_vpns']
+ vpn_wrapper_pids = set()
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)
+
config_path = "/var/lib/0tdns/{}.ovpn".format(config_hash)
physical_ip = get_default_host_address(ztdns_config['host'])
route_through_veth = ztdns_config['host'] + "/32"
@@ -81,9 +91,8 @@ with open("/var/log/0tdns.log", "w") as logfile:
p = subprocess.Popen([wrapper, config_path, physical_ip,
route_through_veth] + command_in_namespace)
-
- subprocesses.append(p)
- sleep(5)
- for p in subprocesses:
- p.wait()
+ vpn_wrapper_pids.add(p.pid)
+
+ for pid in vpn_wrapper_pids:
+ waitpid(pid, 0)