forked from Deuxfleurs/mknet
Some fixes
This commit is contained in:
parent
c016ccdffa
commit
9df55cd46b
3 changed files with 23 additions and 37 deletions
|
@ -1,5 +1,5 @@
|
|||
#!/bin/python3
|
||||
import yaml, os, sys, time, pathlib, unshare, socket, shutil
|
||||
#!/usr/bin/env python3
|
||||
import json, yaml, os, sys, time, pathlib, socket, shutil
|
||||
|
||||
STORAGE_PATH = os.path.join(os.getcwd(), '.minio-testnet')
|
||||
#STORAGE_PATH = os.path.join('/mnt/windows', '.minio-testnet')
|
||||
|
@ -9,8 +9,6 @@ UNIX_SOCK = os.path.join(STORAGE_PATH, 'deploy.sock')
|
|||
DATA_PATH = lambda nid: os.path.join(STORAGE_PATH, 'data'+str(nid))
|
||||
|
||||
def main():
|
||||
unshare.unshare(unshare.CLONE_NEWNS)
|
||||
os.system("mount --make-rprivate /") # see https://stackoverflow.com/a/41580252
|
||||
if int(os.environ['ID']) == 1: leader()
|
||||
else: follower()
|
||||
|
||||
|
@ -27,20 +25,17 @@ def leader():
|
|||
n_serv = n_servers()
|
||||
fl = [ co for co, addr in [ sock.accept() for i in range(n_serv - 1) ]]
|
||||
|
||||
ips = [ co.makefile().readline().strip() for co in fl ] + [ os.environ['IP'] ]
|
||||
print(f"ips: {ips}")
|
||||
gen_hosts(ips)
|
||||
[ co.send(f"{n_serv}\n".encode()) for co in fl ]
|
||||
identities = [ json.loads(co.makefile().readline()) for co in fl ] + [ { "ip": os.environ['IP'], "path": make_data() } ]
|
||||
print(f"ident: {identities}")
|
||||
msg = f"{json.dumps(identities)}\n".encode()
|
||||
[ co.send(msg) for co in fl ]
|
||||
|
||||
mount_hosts()
|
||||
mount_disk()
|
||||
|
||||
run_minio(n_serv)
|
||||
run_minio(identities)
|
||||
|
||||
def follower():
|
||||
co = None
|
||||
while True:
|
||||
time.sleep(3)
|
||||
time.sleep(1)
|
||||
try:
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.connect(UNIX_SOCK)
|
||||
|
@ -48,26 +43,24 @@ def follower():
|
|||
break
|
||||
except Exception as err:
|
||||
print('conn failed, wait,', err)
|
||||
sock.send(f"{os.environ['IP']}\n".encode())
|
||||
n_serv = int(co.readline())
|
||||
my_identity = json.dumps({ "ip": os.environ['IP'], "path": make_data() })
|
||||
sock.send(f"{my_identity}\n".encode())
|
||||
identities = json.loads(co.readline())
|
||||
|
||||
mount_hosts()
|
||||
mount_disk()
|
||||
run_minio(identities)
|
||||
|
||||
run_minio(n_serv)
|
||||
def make_data():
|
||||
data_path = DATA_PATH(os.environ['ID'])
|
||||
os.makedirs(data_path)
|
||||
return data_path
|
||||
|
||||
def run_minio(count):
|
||||
def run_minio(identities):
|
||||
cmd = f"minio server --console-address ':9001' --address [{os.environ['IP']}]:9000"
|
||||
for i in range(1,count+1):
|
||||
cmd += f" http://minio{i}:9000{DATA_PATH(i)}"
|
||||
for ident in identities:
|
||||
cmd += f" http://[{ident['ip']}]:9000{ident['path']}"
|
||||
cmd += f" > {os.path.join(STORAGE_PATH, 'minio'+os.environ['ID']+'.log')} 2>&1"
|
||||
print("launch: ", cmd)
|
||||
os.system(cmd)
|
||||
print("done: ", cmd)
|
||||
|
||||
def gen_hosts(ips):
|
||||
with open(HOSTS_PATH, 'w') as f:
|
||||
for idx,ip in enumerate(ips):
|
||||
f.write(f"{ip} minio{idx+1}\n")
|
||||
|
||||
def n_servers():
|
||||
with open('.current_state.yml', 'r') as f:
|
||||
|
@ -75,11 +68,4 @@ def n_servers():
|
|||
n_servers = len(netw['servers'])
|
||||
return n_servers
|
||||
|
||||
def mount_disk():
|
||||
data_path = DATA_PATH(os.environ['ID'])
|
||||
os.makedirs(data_path)
|
||||
|
||||
def mount_hosts():
|
||||
os.system(f"mount --bind {HOSTS_PATH} /etc/hosts")
|
||||
|
||||
__name__ == '__main__' and main()
|
||||
|
|
|
@ -4,4 +4,4 @@ export ENDPOINT=[fc00:9a7a:9e::1]:9000
|
|||
export AWS_ACCESS_KEY_ID=minioadmin
|
||||
export AWS_SECRET_ACCESS_KEY=minioadmin
|
||||
|
||||
/home/quentin/go/bin/s3lat | tee 50ms.minio.csv
|
||||
s3lat | tee 50ms.minio.csv
|
||||
|
|
4
main.py
4
main.py
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env python
|
||||
#!/usr/bin/env python
|
||||
import ipaddress
|
||||
import os
|
||||
import shutil
|
||||
|
@ -305,7 +305,7 @@ def run(netns, cmd):
|
|||
|
||||
if len(cmd) == 0:
|
||||
cmd = [os.getenv("SHELL") or "/bin/sh"]
|
||||
os.execve("/bin/env", ["/bin/env", "ip", "netns" , "exec", name ] + cmd, env)
|
||||
os.execve("/usr/bin/env", ["/usr/bin/env", "ip", "netns" , "exec", name ] + cmd, env)
|
||||
|
||||
def runall(cmd):
|
||||
with open(".current_state.yml", "r") as file:
|
||||
|
|
Loading…
Add table
Reference in a new issue