disable verbose printing

This commit is contained in:
root 2020-04-10 17:03:45 -04:00
parent 2a025ffa94
commit ad1b3fa4d3
2 changed files with 15 additions and 17 deletions

View File

@ -117,7 +117,7 @@ class OManager:
if exist_running_instance:
lb_cmd = ["go-socks-lb/go-socks-lb", "-config",
lb_cfg_fp, "-bind", "0.0.0.0:7000"]
print("lb_cmd", lb_cmd)
#print("lb_cmd", lb_cmd)
self.run_task.append(self.loop.create_task(
self.run_cmd(lb_cmd)))
#print("pre calc weights:", self.calc_weights())
@ -132,7 +132,7 @@ class OManager:
ping_stat = i["op"].get_ping_stat(
).splitlines()[-max(n_up, n_down):]
ping_stat = [i.split(",")[-1] != "-1" for i in ping_stat]
print("ping status:", ping_stat)
#print("ping status:", ping_stat)
def all_equal(n, status):
for j in range(min(n, len(ping_stat))):
if ping_stat[-(j+1)] != status:
@ -141,11 +141,10 @@ class OManager:
# all up
if all_equal(n_up, True):
i["weight"] = 1
print("all_up")
#print("all_up")
if all_equal(n_down, False):
i["weight"] = 0
print("all_down")
#print("all_down")
weights.append(i["weight"])
return weights
@ -153,9 +152,9 @@ class OManager:
old_weights = []
while True:
await asyncio.sleep(5)
print("calculating weights")
#print("calculating weights")
new_weights = self.calc_weights()
print("finished calc")
#print("finished calc")
if old_weights != new_weights:
old_weights = new_weights
print("weight changed, new weights:", new_weights)
@ -165,8 +164,8 @@ class OManager:
os.kill(self.PID, signal.SIGUSR1)
except:
print("error applying weights")
else:
print("weight not changed, weights:", new_weights)
#else:
#print("weight not changed, weights:", new_weights)
async def run_cmd(self, cmd):
while True:
@ -175,10 +174,9 @@ class OManager:
cmd[0], *cmd[1:],
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)
print("Manager started", cmd)
self.proc = proc
self.PID = proc.pid
print(f"pid: {self.PID}")
print(f"Load balancer started, pid: {self.PID}")
stdout, stderr = await proc.communicate()
print(f'[{cmd!r} exited with {proc.returncode}]')
if stdout:

View File

@ -231,7 +231,7 @@ class Openvpn:
f"{datetime.utcnow().timestamp()},{result}\n")
async def monitor_task(self):
print("running monitor task")
#print("running monitor task")
while self.status == RUNNING:
try:
self.monitor_action()
@ -240,9 +240,9 @@ class Openvpn:
await asyncio.sleep(5)
async def run_cmd(self, cmd, group):
print(f"run: {cmd}")
#print(f"run: {cmd}")
while self.status == RUNNING:
print("create proc")
#print("create proc")
print(self.status)
pid_fp = os.path.join(self.folder_path, f"{cmd[0]}_pid.txt")
try:
@ -250,12 +250,12 @@ class Openvpn:
except:
pass
shell = f"sg {group} -c \"echo \\$\\$ > {pid_fp}; exec {cmd}\""
print(shell)
#print(shell)
proc = await asyncio.create_subprocess_shell(
shell,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)
print("started")
print("openpvn started")
self.proc = proc
for i in range(3):
await asyncio.sleep(1)
@ -270,7 +270,7 @@ class Openvpn:
if not got_pid:
print("error, cannot get pid")
break
print(f"pid: {PID}")
print(f"openvpn pid: {PID}")
self.pids.append(PID)
stdout, stderr = await proc.communicate()
print(f'[{cmd!r} exited with {proc.returncode}]')