From a13c37049a4a9c38ccc3acb0d78ed2717a29244c Mon Sep 17 00:00:00 2001 From: Quentin Date: Wed, 8 Dec 2021 15:43:59 +0100 Subject: Add minio, a README and some small enhancements --- example/deploy_garage.sh | 8 +++--- example/deploy_minio.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100755 example/deploy_minio.py (limited to 'example') diff --git a/example/deploy_garage.sh b/example/deploy_garage.sh index e91b387..0dc9b38 100755 --- a/example/deploy_garage.sh +++ b/example/deploy_garage.sh @@ -46,15 +46,15 @@ EOF RUST_LOG=garage=debug ${GARAGE_PATH} server 2>> ${NODE_STORAGE_PATH}/logs & disown sleep 2 -CONFIG_NODE_FPATH=(${STORAGE_PATH}/*{,/*}/garage.toml) +CONFIG_NODE_FPATH=$(find /tmp/garage-testnet/ -maxdepth 3 -name garage.toml|head -n 1) SELF_ID=$(${GARAGE_PATH} node id 2>/dev/null) SHORT_ID=$(echo ${SELF_ID} | cut -c-64) -${GARAGE_PATH} -c ${CONFIG_NODE_FPATH[0]} node connect ${SELF_ID} -${GARAGE_PATH} -c ${CONFIG_NODE_FPATH[0]} layout assign ${SHORT_ID} -z ${ZONE:-unzonned-${HOST}} -c 1 -t ${HOST} +${GARAGE_PATH} -c ${CONFIG_NODE_FPATH} node connect ${SELF_ID} +${GARAGE_PATH} -c ${CONFIG_NODE_FPATH} layout assign ${SHORT_ID} -z ${ZONE:-unzonned-${HOST}} -c 1 -t ${HOST} -if [ ${CONFIG_NODE_FPATH[0]} == ${GARAGE_CONFIG_FILE} ]; then +if [ ${CONFIG_NODE_FPATH} == ${GARAGE_CONFIG_FILE} ]; then sleep 2 ${GARAGE_PATH} layout show ${GARAGE_PATH} layout apply --version 1 diff --git a/example/deploy_minio.py b/example/deploy_minio.py new file mode 100755 index 0000000..8ee8430 --- /dev/null +++ b/example/deploy_minio.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +import json, os, sys, time, pathlib, socket, shutil + +STORAGE_PATH = os.path.join(os.getcwd(), '.minio-testnet') +MINIO_PATH = '/srv' +HOSTS_PATH = os.path.join(STORAGE_PATH, 'hosts.txt') +UNIX_SOCK = os.path.join(STORAGE_PATH, 'deploy.sock') +DATA_PATH = lambda nid: os.path.join(STORAGE_PATH, 'data'+str(nid)) + +def main(): + if int(os.environ['ID']) == 1: leader() + else: follower() + +def leader(): + shutil.rmtree(STORAGE_PATH, ignore_errors=True) + os.makedirs(STORAGE_PATH) + os.makedirs(MINIO_PATH, exist_ok=True) + print(STORAGE_PATH) + + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.bind(UNIX_SOCK) + sock.listen() + + n_serv = os.environ['SIZE'] + fl = [ co for co, addr in [ sock.accept() for i in range(n_serv - 1) ]] + + 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 ] + + run_minio(identities) + +def follower(): + co = None + while True: + time.sleep(1) + try: + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.connect(UNIX_SOCK) + co = sock.makefile() + break + except Exception as err: + print('conn failed, wait,', err) + my_identity = json.dumps({ "ip": os.environ['IP'], "path": make_data() }) + sock.send(f"{my_identity}\n".encode()) + identities = json.loads(co.readline()) + + run_minio(identities) + +def make_data(): + data_path = DATA_PATH(os.environ['ID']) + os.makedirs(data_path) + return data_path + +def run_minio(identities): + cmd = f"minio server --console-address ':9001' --address [{os.environ['IP']}]:9000" + 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) + +__name__ == '__main__' and main() -- cgit v1.2.3 From 69871eeee82c5e95e28fa94555a774d415cfdd90 Mon Sep 17 00:00:00 2001 From: Quentin Date: Wed, 8 Dec 2021 16:36:33 +0100 Subject: Remove MINIO_PATH --- example/deploy_minio.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'example') diff --git a/example/deploy_minio.py b/example/deploy_minio.py index 8ee8430..4488974 100755 --- a/example/deploy_minio.py +++ b/example/deploy_minio.py @@ -2,7 +2,6 @@ import json, os, sys, time, pathlib, socket, shutil STORAGE_PATH = os.path.join(os.getcwd(), '.minio-testnet') -MINIO_PATH = '/srv' HOSTS_PATH = os.path.join(STORAGE_PATH, 'hosts.txt') UNIX_SOCK = os.path.join(STORAGE_PATH, 'deploy.sock') DATA_PATH = lambda nid: os.path.join(STORAGE_PATH, 'data'+str(nid)) @@ -14,7 +13,6 @@ def main(): def leader(): shutil.rmtree(STORAGE_PATH, ignore_errors=True) os.makedirs(STORAGE_PATH) - os.makedirs(MINIO_PATH, exist_ok=True) print(STORAGE_PATH) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) -- cgit v1.2.3 From 9719f4b294b4d295ed62848c3a82a5271eb86139 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 13 Dec 2021 10:53:42 +0100 Subject: Change env name + fix python casting --- example/deploy_minio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'example') diff --git a/example/deploy_minio.py b/example/deploy_minio.py index 4488974..431b983 100755 --- a/example/deploy_minio.py +++ b/example/deploy_minio.py @@ -19,7 +19,7 @@ def leader(): sock.bind(UNIX_SOCK) sock.listen() - n_serv = os.environ['SIZE'] + n_serv = int(os.environ['SERVER_COUNT']) fl = [ co for co, addr in [ sock.accept() for i in range(n_serv - 1) ]] identities = [ json.loads(co.makefile().readline()) for co in fl ] + [ { "ip": os.environ['IP'], "path": make_data() } ] @@ -52,7 +52,7 @@ def make_data(): return data_path def run_minio(identities): - cmd = f"minio server --console-address ':9001' --address [{os.environ['IP']}]:9000" + cmd = f"minio server --console-address ':9001' --address ':9000'" 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" -- cgit v1.2.3