-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_cluster.sh
More file actions
37 lines (28 loc) · 1.24 KB
/
create_cluster.sh
File metadata and controls
37 lines (28 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
#
# Script to bootstrap a 3-node Chord.py ring using Docker.
#
function teardown() {
echo "Running cleanup..."
docker container stop chordpy_node1 chordpy_node2 chordpy_node3 > /dev/null 2>&1
docker container rm chordpy_node1 chordpy_node2 chordpy_node3 > /dev/null 2>&1
docker network rm chordnet > /dev/null 2>&1
}
# Tear down any remaining resources in case of unclean shutdown
teardown
# Re-build local image
docker image build -t chordpy .
# Create local network for nodes
docker network create --internal chordnet
# Run containers
docker container run --detach --hostname node1 --name chordpy_node1 --network chordnet chordpy
docker container run --detach --hostname node2 --name chordpy_node2 --network chordnet chordpy
docker container run --detach --hostname node3 --name chordpy_node3 --network chordnet chordpy
# Bootstrap cluster
docker container exec chordpy_node1 python -m chord.http.client node1 5000 create
docker container exec chordpy_node2 python -m chord.http.client node2 5000 join node1 5000
docker container exec chordpy_node3 python -m chord.http.client node3 5000 join node1 5000
# Open an interactive terminal on node3
docker container exec -it chordpy_node3 /bin/bash
# Silently tear down resources
teardown