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
|
#!/usr/bin/env python3
|
||||||
import yaml, os, sys, time, pathlib, unshare, socket, shutil
|
import json, yaml, os, sys, time, pathlib, socket, shutil
|
||||||
|
|
||||||
STORAGE_PATH = os.path.join(os.getcwd(), '.minio-testnet')
|
STORAGE_PATH = os.path.join(os.getcwd(), '.minio-testnet')
|
||||||
#STORAGE_PATH = os.path.join('/mnt/windows', '.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))
|
DATA_PATH = lambda nid: os.path.join(STORAGE_PATH, 'data'+str(nid))
|
||||||
|
|
||||||
def main():
|
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()
|
if int(os.environ['ID']) == 1: leader()
|
||||||
else: follower()
|
else: follower()
|
||||||
|
|
||||||
|
@ -27,20 +25,17 @@ def leader():
|
||||||
n_serv = n_servers()
|
n_serv = n_servers()
|
||||||
fl = [ co for co, addr in [ sock.accept() for i in range(n_serv - 1) ]]
|
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'] ]
|
identities = [ json.loads(co.makefile().readline()) for co in fl ] + [ { "ip": os.environ['IP'], "path": make_data() } ]
|
||||||
print(f"ips: {ips}")
|
print(f"ident: {identities}")
|
||||||
gen_hosts(ips)
|
msg = f"{json.dumps(identities)}\n".encode()
|
||||||
[ co.send(f"{n_serv}\n".encode()) for co in fl ]
|
[ co.send(msg) for co in fl ]
|
||||||
|
|
||||||
mount_hosts()
|
run_minio(identities)
|
||||||
mount_disk()
|
|
||||||
|
|
||||||
run_minio(n_serv)
|
|
||||||
|
|
||||||
def follower():
|
def follower():
|
||||||
co = None
|
co = None
|
||||||
while True:
|
while True:
|
||||||
time.sleep(3)
|
time.sleep(1)
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
sock.connect(UNIX_SOCK)
|
sock.connect(UNIX_SOCK)
|
||||||
|
@ -48,26 +43,24 @@ def follower():
|
||||||
break
|
break
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print('conn failed, wait,', err)
|
print('conn failed, wait,', err)
|
||||||
sock.send(f"{os.environ['IP']}\n".encode())
|
my_identity = json.dumps({ "ip": os.environ['IP'], "path": make_data() })
|
||||||
n_serv = int(co.readline())
|
sock.send(f"{my_identity}\n".encode())
|
||||||
|
identities = json.loads(co.readline())
|
||||||
|
|
||||||
mount_hosts()
|
run_minio(identities)
|
||||||
mount_disk()
|
|
||||||
|
|
||||||
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"
|
cmd = f"minio server --console-address ':9001' --address [{os.environ['IP']}]:9000"
|
||||||
for i in range(1,count+1):
|
for ident in identities:
|
||||||
cmd += f" http://minio{i}:9000{DATA_PATH(i)}"
|
cmd += f" http://[{ident['ip']}]:9000{ident['path']}"
|
||||||
cmd += f" > {os.path.join(STORAGE_PATH, 'minio'+os.environ['ID']+'.log')} 2>&1"
|
cmd += f" > {os.path.join(STORAGE_PATH, 'minio'+os.environ['ID']+'.log')} 2>&1"
|
||||||
|
print("launch: ", cmd)
|
||||||
os.system(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():
|
def n_servers():
|
||||||
with open('.current_state.yml', 'r') as f:
|
with open('.current_state.yml', 'r') as f:
|
||||||
|
@ -75,11 +68,4 @@ def n_servers():
|
||||||
n_servers = len(netw['servers'])
|
n_servers = len(netw['servers'])
|
||||||
return n_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()
|
__name__ == '__main__' and main()
|
||||||
|
|
|
@ -4,4 +4,4 @@ export ENDPOINT=[fc00:9a7a:9e::1]:9000
|
||||||
export AWS_ACCESS_KEY_ID=minioadmin
|
export AWS_ACCESS_KEY_ID=minioadmin
|
||||||
export AWS_SECRET_ACCESS_KEY=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 ipaddress
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -305,7 +305,7 @@ def run(netns, cmd):
|
||||||
|
|
||||||
if len(cmd) == 0:
|
if len(cmd) == 0:
|
||||||
cmd = [os.getenv("SHELL") or "/bin/sh"]
|
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):
|
def runall(cmd):
|
||||||
with open(".current_state.yml", "r") as file:
|
with open(".current_state.yml", "r") as file:
|
||||||
|
|
Loading…
Reference in a new issue