disable verbose printing
This commit is contained in:
parent
2a025ffa94
commit
ad1b3fa4d3
20
o_manager.py
20
o_manager.py
@ -117,7 +117,7 @@ class OManager:
|
|||||||
if exist_running_instance:
|
if exist_running_instance:
|
||||||
lb_cmd = ["go-socks-lb/go-socks-lb", "-config",
|
lb_cmd = ["go-socks-lb/go-socks-lb", "-config",
|
||||||
lb_cfg_fp, "-bind", "0.0.0.0:7000"]
|
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_task.append(self.loop.create_task(
|
||||||
self.run_cmd(lb_cmd)))
|
self.run_cmd(lb_cmd)))
|
||||||
#print("pre calc weights:", self.calc_weights())
|
#print("pre calc weights:", self.calc_weights())
|
||||||
@ -132,7 +132,7 @@ class OManager:
|
|||||||
ping_stat = i["op"].get_ping_stat(
|
ping_stat = i["op"].get_ping_stat(
|
||||||
).splitlines()[-max(n_up, n_down):]
|
).splitlines()[-max(n_up, n_down):]
|
||||||
ping_stat = [i.split(",")[-1] != "-1" for i in ping_stat]
|
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):
|
def all_equal(n, status):
|
||||||
for j in range(min(n, len(ping_stat))):
|
for j in range(min(n, len(ping_stat))):
|
||||||
if ping_stat[-(j+1)] != status:
|
if ping_stat[-(j+1)] != status:
|
||||||
@ -141,11 +141,10 @@ class OManager:
|
|||||||
# all up
|
# all up
|
||||||
if all_equal(n_up, True):
|
if all_equal(n_up, True):
|
||||||
i["weight"] = 1
|
i["weight"] = 1
|
||||||
print("all_up")
|
#print("all_up")
|
||||||
if all_equal(n_down, False):
|
if all_equal(n_down, False):
|
||||||
i["weight"] = 0
|
i["weight"] = 0
|
||||||
print("all_down")
|
#print("all_down")
|
||||||
|
|
||||||
weights.append(i["weight"])
|
weights.append(i["weight"])
|
||||||
return weights
|
return weights
|
||||||
|
|
||||||
@ -153,9 +152,9 @@ class OManager:
|
|||||||
old_weights = []
|
old_weights = []
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
print("calculating weights")
|
#print("calculating weights")
|
||||||
new_weights = self.calc_weights()
|
new_weights = self.calc_weights()
|
||||||
print("finished calc")
|
#print("finished calc")
|
||||||
if old_weights != new_weights:
|
if old_weights != new_weights:
|
||||||
old_weights = new_weights
|
old_weights = new_weights
|
||||||
print("weight changed, new weights:", new_weights)
|
print("weight changed, new weights:", new_weights)
|
||||||
@ -165,8 +164,8 @@ class OManager:
|
|||||||
os.kill(self.PID, signal.SIGUSR1)
|
os.kill(self.PID, signal.SIGUSR1)
|
||||||
except:
|
except:
|
||||||
print("error applying weights")
|
print("error applying weights")
|
||||||
else:
|
#else:
|
||||||
print("weight not changed, weights:", new_weights)
|
#print("weight not changed, weights:", new_weights)
|
||||||
|
|
||||||
async def run_cmd(self, cmd):
|
async def run_cmd(self, cmd):
|
||||||
while True:
|
while True:
|
||||||
@ -175,10 +174,9 @@ class OManager:
|
|||||||
cmd[0], *cmd[1:],
|
cmd[0], *cmd[1:],
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE)
|
stderr=asyncio.subprocess.PIPE)
|
||||||
print("Manager started", cmd)
|
|
||||||
self.proc = proc
|
self.proc = proc
|
||||||
self.PID = proc.pid
|
self.PID = proc.pid
|
||||||
print(f"pid: {self.PID}")
|
print(f"Load balancer started, pid: {self.PID}")
|
||||||
stdout, stderr = await proc.communicate()
|
stdout, stderr = await proc.communicate()
|
||||||
print(f'[{cmd!r} exited with {proc.returncode}]')
|
print(f'[{cmd!r} exited with {proc.returncode}]')
|
||||||
if stdout:
|
if stdout:
|
||||||
|
|||||||
12
openvpn.py
12
openvpn.py
@ -231,7 +231,7 @@ class Openvpn:
|
|||||||
f"{datetime.utcnow().timestamp()},{result}\n")
|
f"{datetime.utcnow().timestamp()},{result}\n")
|
||||||
|
|
||||||
async def monitor_task(self):
|
async def monitor_task(self):
|
||||||
print("running monitor task")
|
#print("running monitor task")
|
||||||
while self.status == RUNNING:
|
while self.status == RUNNING:
|
||||||
try:
|
try:
|
||||||
self.monitor_action()
|
self.monitor_action()
|
||||||
@ -240,9 +240,9 @@ class Openvpn:
|
|||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
async def run_cmd(self, cmd, group):
|
async def run_cmd(self, cmd, group):
|
||||||
print(f"run: {cmd}")
|
#print(f"run: {cmd}")
|
||||||
while self.status == RUNNING:
|
while self.status == RUNNING:
|
||||||
print("create proc")
|
#print("create proc")
|
||||||
print(self.status)
|
print(self.status)
|
||||||
pid_fp = os.path.join(self.folder_path, f"{cmd[0]}_pid.txt")
|
pid_fp = os.path.join(self.folder_path, f"{cmd[0]}_pid.txt")
|
||||||
try:
|
try:
|
||||||
@ -250,12 +250,12 @@ class Openvpn:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
shell = f"sg {group} -c \"echo \\$\\$ > {pid_fp}; exec {cmd}\""
|
shell = f"sg {group} -c \"echo \\$\\$ > {pid_fp}; exec {cmd}\""
|
||||||
print(shell)
|
#print(shell)
|
||||||
proc = await asyncio.create_subprocess_shell(
|
proc = await asyncio.create_subprocess_shell(
|
||||||
shell,
|
shell,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE)
|
stderr=asyncio.subprocess.PIPE)
|
||||||
print("started")
|
print("openpvn started")
|
||||||
self.proc = proc
|
self.proc = proc
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
@ -270,7 +270,7 @@ class Openvpn:
|
|||||||
if not got_pid:
|
if not got_pid:
|
||||||
print("error, cannot get pid")
|
print("error, cannot get pid")
|
||||||
break
|
break
|
||||||
print(f"pid: {PID}")
|
print(f"openvpn pid: {PID}")
|
||||||
self.pids.append(PID)
|
self.pids.append(PID)
|
||||||
stdout, stderr = await proc.communicate()
|
stdout, stderr = await proc.communicate()
|
||||||
print(f'[{cmd!r} exited with {proc.returncode}]')
|
print(f'[{cmd!r} exited with {proc.returncode}]')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user